帮助在关联表的情况下在 Castle Active Record 中配置关联
我有像
Users (UserId,Username,Password,CreatedOn,CreatedBy)
Roles (RoleId,RoleName,Description,CreatedOn,CreatedBy)
UserRoleMap(UserRoleMapId,UserId,RoleId,CreatedOn,CreatedBy)
这样的表,这些是我的实体:
[ActiveRecord(Table="Users")]
public class User:ActiveRecordBase<User>
{
[PrimaryKey(Generator = PrimaryKeyType.Identity, Column = "RoleId")]
public virtual int UserId { get; set; }
[Property(Column="Username")]
public virtual string Username { get; set; }
[Property(Column = "Password")]
public virtual string Password { get; set; }
[Property(Column="CreatedBy")]
public virtual string CreatedBy { get; set; }
[Property(Column="CreatedOn")]
public virtual DateTime CreatedOn { get; set; }
[HasAndBelongsToMany(Table="UserRoleMap",ColumnKey="UserId")]
public IList<Role> Roles { get; set; }
}
[ActiveRecord(Table = "Roles")]
public class Role : ActiveRecordBase<User>
{
[PrimaryKey(Generator = PrimaryKeyType.Identity, Column = "RoleId")]
public virtual int RoleId { get; set; }
[Property(Column = "RoleName")]
public virtual string RoleName { get; set; }
[Property(Column = "Description")]
public virtual string Description { get; set; }
[Property(Column = "CreatedBy")]
public virtual string CreatedBy { get; set; }
[Property(Column = "CreatedOn")]
public virtual DateTime CreatedOn { get; set; }
[HasAndBelongsToMany(Table = "UserRoleMap", ColumnKey = "RoleId")]
public IList<User> Users { get; set; }
}
[ActiveRecord(Table="UserRoleMap")]
public class UserRoleMap:ActiveRecordBase<UserRoleMap>
{
[PrimaryKey(Generator = PrimaryKeyType.Identity, Column = "UserRoleMapId")]
public virtual int UserRoleMapId { get; set; }
[BelongsTo(Column="UserId",Table="Users")]
public virtual User UserId { get; set; }
[BelongsTo(Column = "RoleId", Table = "Roles")]
public virtual Role RoleId { get; set; }
}
我不断收到此错误: ActiveRecordSample.Tests.FrameworkInitializationTest.CanInitializaFramework : Castle.ActiveRecord.Framework.ActiveRecordException : 属性 UserId 引用表“Users”,该表在类上没有相应的 [JoinedTable]。
I have tables like
Users (UserId,Username,Password,CreatedOn,CreatedBy)
Roles (RoleId,RoleName,Description,CreatedOn,CreatedBy)
UserRoleMap(UserRoleMapId,UserId,RoleId,CreatedOn,CreatedBy)
These are my entities:
[ActiveRecord(Table="Users")]
public class User:ActiveRecordBase<User>
{
[PrimaryKey(Generator = PrimaryKeyType.Identity, Column = "RoleId")]
public virtual int UserId { get; set; }
[Property(Column="Username")]
public virtual string Username { get; set; }
[Property(Column = "Password")]
public virtual string Password { get; set; }
[Property(Column="CreatedBy")]
public virtual string CreatedBy { get; set; }
[Property(Column="CreatedOn")]
public virtual DateTime CreatedOn { get; set; }
[HasAndBelongsToMany(Table="UserRoleMap",ColumnKey="UserId")]
public IList<Role> Roles { get; set; }
}
[ActiveRecord(Table = "Roles")]
public class Role : ActiveRecordBase<User>
{
[PrimaryKey(Generator = PrimaryKeyType.Identity, Column = "RoleId")]
public virtual int RoleId { get; set; }
[Property(Column = "RoleName")]
public virtual string RoleName { get; set; }
[Property(Column = "Description")]
public virtual string Description { get; set; }
[Property(Column = "CreatedBy")]
public virtual string CreatedBy { get; set; }
[Property(Column = "CreatedOn")]
public virtual DateTime CreatedOn { get; set; }
[HasAndBelongsToMany(Table = "UserRoleMap", ColumnKey = "RoleId")]
public IList<User> Users { get; set; }
}
[ActiveRecord(Table="UserRoleMap")]
public class UserRoleMap:ActiveRecordBase<UserRoleMap>
{
[PrimaryKey(Generator = PrimaryKeyType.Identity, Column = "UserRoleMapId")]
public virtual int UserRoleMapId { get; set; }
[BelongsTo(Column="UserId",Table="Users")]
public virtual User UserId { get; set; }
[BelongsTo(Column = "RoleId", Table = "Roles")]
public virtual Role RoleId { get; set; }
}
I keep getting this error:
ActiveRecordSample.Tests.FrameworkInitializationTest.CanInitializaFramework : Castle.ActiveRecord.Framework.ActiveRecordException : Property UserId references table "Users", which does not have a corresponding [JoinedTable] on the class.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)