Subsonic 亚音速3-简单存储库和创建外键
似乎几乎没有任何例子,因此: 下面是我的三个结构,但它似乎无法正确创建表,当我调用下面的行时,它表示Id无法识别:Subsonic 亚音速3-简单存储库和创建外键,subsonic,foreign-key-relationship,subsonic-simplerepository,Subsonic,Foreign Key Relationship,Subsonic Simplerepository,似乎几乎没有任何例子,因此: 下面是我的三个结构,但它似乎无法正确创建表,当我调用下面的行时,它表示Id无法识别: IEnumerable<Permission> permissions = _data.Find<RolePermission>(x => x.Role.RoleKey == roleKey).Select(x => x.Permission); 许可: public class RolePermission { [SubSonicP
IEnumerable<Permission> permissions = _data.Find<RolePermission>(x => x.Role.RoleKey == roleKey).Select(x => x.Permission);
许可:
public class RolePermission
{
[SubSonicPrimaryKey]
public int RolePermissionId { get; set; }
public int RoleId { get; set; }
public int PermissionId { get; set; }
//Foreign Key of Role
public Role Role { get; set; }
//Foreign key of Permission
public Permission Permission { get; set; }
}
public class Permission
{
[SubSonicPrimaryKey]
public int Id { get; set; }
[SubSonicLongString]
public string PermissionKey { get; set; }
[SubSonicLongString]
public string PermissionDescription { get; set; }
}
角色:
我不知道这是否已经在当前版本中修复,但我记得在亚音速的主键检测中有一个愚蠢的错误
- 如果对象包含名为Id subsonic的属性,则假定该属性是主键
- 如果不是,你必须通过使用
属性装饰一个属性来告诉subsonic with是你的主键(就像你做的那样)SubSonicPrimaryKey
- 如果您有一个名为Id的属性,并且该属性也用属性(如您的角色和权限类)修饰,则subsonic会两次查找该属性,并且不会检查它们是否都相等。然后它抛出一个异常,因为它无法可靠地确定采取哪种异常
public class Role
{
[SubSonicPrimaryKey]
public int Id { get; set; }
[SubSonicLongString]
public string RoleKey { get; set; }
[SubSonicLongString]
public string RoleDescription { get; set; }
}