[英]ado.net Linq query with join table
Here is my edmx diagram. 这是我的edmx图。
I am trying to use 我正在尝试使用
UserEntity.users.ToList<user>();
This provides me with a complex object of User
s that contain user_groups
, but I can't seem to find the Group
information. 这为我提供了一个包含
user_groups
的User
的复杂对象,但我似乎无法找到Group
信息。 My understanding is that EF is supposed to abstract out the join table and provide me with direct access to the Group
information. 我的理解是EF应该抽象出连接表并让我直接访问
Group
信息。 Please note I am coming from cakephp and hoping for a similar style result! 请注意我来自cakephp,并希望有类似的风格结果!
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>();
}
}
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. users
和user_group
之间存在一对多关系,因此您可以从users
选择一个user_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. users
的导航属性user_group
将具有user_group
对象的集合,您可以根据您的要求选择First
或任何内容,然后从那里选择group
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.