Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
CODE PROJECT For Those Who Code
  • Home
  • Articles
  • FAQ
Community
  1. Home
  2. Web Development
  3. ASP.NET
  4. How to assign role to linq queries?

How to assign role to linq queries?

Scheduled Pinned Locked Moved ASP.NET
databaselinqquestioncsharpsysadmin
5 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • M Offline
    M Offline
    miss786
    wrote on last edited by
    #1

    Dear all, I am writing to seek assistant, in how do I assign my queries below to specific roles. I am currently not storing my roles for any user in my db server. Is this task still plausible? Can this task by done using either using 'string array' roles (i.e. string[] userRoles = new string[] { "full", "trial" }), or using 'Group By' function in linq qeuery?

    public bool full(string username, string password)
    {
    //define the query : query will be an IQueryable
    var query = // query

            // "execute" the query
            return query.FirstOrDefault() != null; 
    
        }
    
    
        public bool trial(string username, string password)
        {
            //define the query : query will be an IQueryable
            var query = // query
    
            // "execute" the query
            return query.FirstOrDefault() != null; 
    
        }
    

    Many thanks for help and time.

    K 1 Reply Last reply
    0
    • M miss786

      Dear all, I am writing to seek assistant, in how do I assign my queries below to specific roles. I am currently not storing my roles for any user in my db server. Is this task still plausible? Can this task by done using either using 'string array' roles (i.e. string[] userRoles = new string[] { "full", "trial" }), or using 'Group By' function in linq qeuery?

      public bool full(string username, string password)
      {
      //define the query : query will be an IQueryable
      var query = // query

              // "execute" the query
              return query.FirstOrDefault() != null; 
      
          }
      
      
          public bool trial(string username, string password)
          {
              //define the query : query will be an IQueryable
              var query = // query
      
              // "execute" the query
              return query.FirstOrDefault() != null; 
      
          }
      

      Many thanks for help and time.

      K Offline
      K Offline
      kaushikpathak
      wrote on last edited by
      #2

      The best practice is to store role in db but you can also store in dictionary

      M 1 Reply Last reply
      0
      • K kaushikpathak

        The best practice is to store role in db but you can also store in dictionary

        M Offline
        M Offline
        miss786
        wrote on last edited by
        #3

        Thank you so much for your response. Is their a way to group or name the queries, so i can compute the following logic:

        if (user & password match from full query)
        {
        return string = "full status"
        }
        else
        {
        return string = "trial status"
        }

        Is their some function or framework i could look into. please help. Thank you

        K 1 Reply Last reply
        0
        • M miss786

          Thank you so much for your response. Is their a way to group or name the queries, so i can compute the following logic:

          if (user & password match from full query)
          {
          return string = "full status"
          }
          else
          {
          return string = "trial status"
          }

          Is their some function or framework i could look into. please help. Thank you

          K Offline
          K Offline
          kaushikpathak
          wrote on last edited by
          #4

          You can simply use switch case. Or its better if you can share your both the queries.

          M 1 Reply Last reply
          0
          • K kaushikpathak

            You can simply use switch case. Or its better if you can share your both the queries.

            M Offline
            M Offline
            miss786
            wrote on last edited by
            #5

            Hi, thank you for your reply back and you suggestion on 'switch back'. I will look into this function. Currently this what my queries look like:

            public User trial(string username, string password)
            {
            string[] roles = new string[] { "trial"};
            var query = from s in db.Subs
            join u in db.Cust on s.sUID equals u.uID
            where s.sExpiryDate >= DateTime.Now &&
            u.uUsername == username &&
            u.uPassword == password
            select u;
            return query.FirstOrDefault();
            }

                public User full(string username, string password)
                {
                    string\[\] roles = new string\[\] { "full"};
                    var query = from s in db.Subs
                                join u in db.Cust on s.sUID equals u.uID
                                u.uUsername == username &&
                                u.uPassword == password
                                select u;
                    return query.FirstOrDefault();
                }
            

            Any help or suggestion, would be really appreciated. Thanks in advance.

            1 Reply Last reply
            0
            Reply
            • Reply as topic
            Log in to reply
            • Oldest to Newest
            • Newest to Oldest
            • Most Votes


            • Login

            • Don't have an account? Register

            • Login or register to search.
            • First post
              Last post
            0
            • Categories
            • Recent
            • Tags
            • Popular
            • World
            • Users
            • Groups