0

Here is my edmx diagram.

enter image description here

I am trying to use

UserEntity.users.ToList<user>();

This provides me with a complex object of Users that contain user_groups, but I can't seem to find the Group information. My understanding is that EF is supposed to abstract out the join table and provide me with direct access to the Group information. Please note I am coming from cakephp and hoping for a similar style result!

Edit: Model Code

 public static class UserModel
    {
        static UserEntities dataContext = new UserEntities();

        public static void CreateUser(user _newUser)
        {
            dataContext.users.AddObject(_newUser);
            dataContext.SaveChanges();
        }

        public static List<user> GetAllUsers()
        {
            return dataContext.users.ToList<user>();
        }
    }
2
  • @Julien...please share your Model code. You need to define the properties and linkages correctly in the Object's .cs files. I'm not clear as to what is it you exactly want. You want to see group and user_groups? Commented Aug 1, 2012 at 18:29
  • Habib's answer at first glance seems like what I need. Thanks much. Commented Aug 1, 2012 at 18:36

1 Answer 1

2

There is one to many relationship between users and user_group, so you may select a single user_group from users and against that you will get group.

var result = users.user_group.FirstOrDefault().group;

The Navigation property user_group in users will have a collection of user_group objects, you may select First or anything based on your requirement and then select group from there.

Sign up to request clarification or add additional context in comments.

2 Comments

I do not have access to group from user_group like this
@Julien, I missed the one to many relationship between users to user_groups, check the edited answer now

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.