Extend a LINQ class with constructor methods RRS feed

  • Question

  • Hello,

    I have two tables UserGroup and User and i'm using Linq to and WCF. I'm trying to get and set the assossiation 'UserGroup' from User. I did this extend class but i need to do the contructor method to get UserGroup from data base.

    public partial class User
        List<UserGroup> _UserGroupRelation;
        DataClassesDataContext DC = new DataClassesDataContext();
        //Contruct Method Here
        //public User()
        //_assignmentRelation = new List<UserGroup>((from temp in DC.UserGroup where temp.ID.Equals(this.GroupID) select temp).ToList());
        public List<UserGroup> UserGroupRelation()
             return _UserGroupRelation;
              _UserGroupRelation = value;

    Thank you.

    Tuesday, July 27, 2010 3:15 PM


  • Hello,

    Linq to SQL will automatically generate the association for you. What's more, it also generate a default constructor for you. you could directly manipulate the UserGroup collection. If you have to create one, you must overload the constructor of you entity, for example, you may need an id parameter to specify which user's UserGroup you want to get.  

    Best regards

    Please remember to mark the replies as answers if they help and unmark them if they provide no help.
    If you have any feedback, please tell us.
    Welcome to the All-In-One Code Framework!
    Thursday, July 29, 2010 11:20 AM