LINQ to SQL Association 1 to N.

时间:2011-02-14 10:05:29

标签: linq-to-sql

如果表UsersInRoles是关系表,我如何更改此数据映射。 (例如,userId = 3,返回5行)。

private EntityRef<UserInRoles> roles;
[Association(Storage = "UsersInRoles", ThisKey = "UserId")]
public UserInRoles Roles
{
    get { return this.roles.Entity; }
    set { this.roles.Entity = value; }
}

THX

1 个答案:

答案 0 :(得分:1)

使用EntitySet而不是EntityRef。

private EntitySet<UserInRoles> _roles;

[Association(Storage="_roles", ThisKey="UserId", OtherKey="UserId")]
public EntitySet<UserInRoles> Roles
{
  get
  {
    return this._roles;
  }
  set
  {
    this._roles.Assign(value);
  }
}