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
  1. Home
  2. Web Development
  3. ASP.NET
  4. Invalid initializer member declarator -- error

Invalid initializer member declarator -- error

Scheduled Pinned Locked Moved ASP.NET
databasehelp
3 Posts 2 Posters 1 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 experiencing the following issue -- Invalid initializer member declarator -- error, on the following line of code. return new ClaimRole() { query.uUsername = user.Username, query.uPassword == user.Password, user.role = "Trial" };

    public UserDetail trial(string username, string password)
    {
    //string[] Role = new string[] { "trial"};

            ClaimRole user = new ClaimRole();
    
            var query = (from s in db.Subscriptions
                        join u in db.UserDetails on s.sUID equals u.uID
                        where s.sExpiryDate >= DateTime.Now &&
                        s.sPID.Value == 163 &&
                        u.uUsername == username &&
                        u.uPassword == password
                        select u).FirstOrDefault();
    
            if (query != null)
            {
                // Build a user and add the appropriate Trial role
                return new ClaimRole() { query.uUsername = user.Username, query.uPassword == user.Password, user.role = "Trial" };
            }
            else
            {
                // No user was found
                return null;
            }
        }
    

    public class ClaimRole
    {

       public string Username { get; set; }
       public string Password { get; set; }
       public string role { get; set; }
    

    }

    User Detail is data model class from EF database. My desired output, is to assign role property to the query. Please advise. Many thanks.

    Richard DeemingR 1 Reply Last reply
    0
    • M miss786

      Dear all, I am experiencing the following issue -- Invalid initializer member declarator -- error, on the following line of code. return new ClaimRole() { query.uUsername = user.Username, query.uPassword == user.Password, user.role = "Trial" };

      public UserDetail trial(string username, string password)
      {
      //string[] Role = new string[] { "trial"};

              ClaimRole user = new ClaimRole();
      
              var query = (from s in db.Subscriptions
                          join u in db.UserDetails on s.sUID equals u.uID
                          where s.sExpiryDate >= DateTime.Now &&
                          s.sPID.Value == 163 &&
                          u.uUsername == username &&
                          u.uPassword == password
                          select u).FirstOrDefault();
      
              if (query != null)
              {
                  // Build a user and add the appropriate Trial role
                  return new ClaimRole() { query.uUsername = user.Username, query.uPassword == user.Password, user.role = "Trial" };
              }
              else
              {
                  // No user was found
                  return null;
              }
          }
      

      public class ClaimRole
      {

         public string Username { get; set; }
         public string Password { get; set; }
         public string role { get; set; }
      

      }

      User Detail is data model class from EF database. My desired output, is to assign role property to the query. Please advise. Many thanks.

      Richard DeemingR Offline
      Richard DeemingR Offline
      Richard Deeming
      wrote on last edited by
      #2

      Your object initializer syntax is messed up. Try:

      return new ClaimRole { Username = query.uUsername, Password = query.uPassword, role = query.role };

      Object and Collection Initializers (C# Programming Guide)[^]


      "These people looked deep within my soul and assigned me a number based on the order in which I joined." - Homer

      "These people looked deep within my soul and assigned me a number based on the order in which I joined" - Homer

      M 1 Reply Last reply
      0
      • Richard DeemingR Richard Deeming

        Your object initializer syntax is messed up. Try:

        return new ClaimRole { Username = query.uUsername, Password = query.uPassword, role = query.role };

        Object and Collection Initializers (C# Programming Guide)[^]


        "These people looked deep within my soul and assigned me a number based on the order in which I joined." - Homer

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

        Many thanks for your reply and help. That worked. :) Apology for incorrect object's syntax. Have a great evening.

        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