Castle Active Record - 一对多关系
我尝试在活动记录中创建多对多关系。
[ActiveRecord("Users")]
public class User : ActiveRecordBase<User>
{
private IList<PhotoAlbum> _albums = new List<PhotoAlbum>();
[PrimaryKey]
public virtual int UserId { get; set; }
[BelongsTo("ProfilId")]
public virtual Profil Profil { get; set; }
[HasMany(Inverse = false,Cascade = ManyRelationCascadeEnum.Delete)]
public IList<PhotoAlbum> Album
{
get { return _albums; }
set { _albums = value; }
}
[Property]
public virtual string Nick { get; set; }
}
[ActiveRecord("Profiles")]
public class Profil : ActiveRecordBase<Profil>
{
[PrimaryKey]
public int ProfilId { get; set; }
[Property]
public int Age { get; set; }
[Property]
public int Sex { get; set; }
[Property]
public string Region { get; set; }
[Property]
public string Town { get; set; }
[Property]
public bool WithPhoto { get; set; }
[Property]
public bool HasPhotoAlbum { get; set; }
}
[ActiveRecord("PhotoAlbums")]
public class PhotoAlbum : ActiveRecordBase<PhotoAlbum>
{
[PrimaryKey]
public int PhotoAlbumId { get; set; }
[Property]
public string Name { get; set; }
[Property]
public int NumberOfPhoto { get; set; }
}
我正在使用 http://www.castleproject.org/activerecord/gettingstarted/relations 中的示例。 html
它完成时出现以下错误:
ActiveRecord 尝试推断有关 User.Album 关系的详细信息,但是 它无法在目标类型中找到“BelongsTo”映射属性
StrackTrace 中找到“BelongsTo”映射属性:
在 Castle.ActiveRecord.Framework.Internal.SemanticVerifierVisitor.VisitHasMany(HasManyModel 型号)在 Castle.ActiveRecord.Framework.Internal.HasManyModel.Accept(IVisitor 访客)在 Castle.ActiveRecord.Framework.Internal.AbstractDepthFirstVisitor.VisitNode(IVisitable 可访问)在 Castle.ActiveRecord.Framework.Internal.AbstractDepthFirstVisitor.VisitNodes(IEnumerable 节点)在 Castle.ActiveRecord.Framework.Internal.AbstractDepthFirstVisitor.VisitModel(ActiveRecordModel 型号)在 Castle.ActiveRecord.Framework.Internal.SemanticVerifierVisitor.VisitModel(ActiveRecordModel 型号)在 Castle.ActiveRecord.Framework.Internal.ActiveRecordModel.Accept(IVisitor 访客)在 Castle.ActiveRecord.Framework.Internal.AbstractDepthFirstVisitor.VisitNode(IVisitable 可访问)在 Castle.ActiveRecord.Framework.Internal.AbstractDepthFirstVisitor.VisitNodes(IEnumerable 节点)在 Castle.ActiveRecord.ActiveRecordStarter.RegisterTypes(ISessionFactoryHolder holder,IConfigurationSource 源,IEnumerable`1 类型,布尔值 忽略ProblematicTypes)在 Castle.ActiveRecord.ActiveRecordStarter.Initialize(IConfigurationSource 源,Type[] 类型)位于 SAMPLE_1.Program.Main(String[] args) 中 E:\C# PROJECTS\STUDY\STUDY.ORM\Active Record
<块引用>SAMPLE_1.相册
我认为问题出在这里:
[HasMany(Inverse = false,Cascade = ManyRelationCascadeEnum.Delete)]
public IList<PhotoAlbum> Album
{
get { return _albums; }
set { _albums = value; }
}
如果我省略了这个属性/关系,它会很好地工作。
I try create many to relationship one to many in Active record.
[ActiveRecord("Users")]
public class User : ActiveRecordBase<User>
{
private IList<PhotoAlbum> _albums = new List<PhotoAlbum>();
[PrimaryKey]
public virtual int UserId { get; set; }
[BelongsTo("ProfilId")]
public virtual Profil Profil { get; set; }
[HasMany(Inverse = false,Cascade = ManyRelationCascadeEnum.Delete)]
public IList<PhotoAlbum> Album
{
get { return _albums; }
set { _albums = value; }
}
[Property]
public virtual string Nick { get; set; }
}
[ActiveRecord("Profiles")]
public class Profil : ActiveRecordBase<Profil>
{
[PrimaryKey]
public int ProfilId { get; set; }
[Property]
public int Age { get; set; }
[Property]
public int Sex { get; set; }
[Property]
public string Region { get; set; }
[Property]
public string Town { get; set; }
[Property]
public bool WithPhoto { get; set; }
[Property]
public bool HasPhotoAlbum { get; set; }
}
[ActiveRecord("PhotoAlbums")]
public class PhotoAlbum : ActiveRecordBase<PhotoAlbum>
{
[PrimaryKey]
public int PhotoAlbumId { get; set; }
[Property]
public string Name { get; set; }
[Property]
public int NumberOfPhoto { get; set; }
}
I am using sample from http://www.castleproject.org/activerecord/gettingstarted/relations.html
it finished with this error:
ActiveRecord tried to infer details about the relation User.Album but
it could not find a 'BelongsTo' mapped property in the target type
StrackTrace:
at
Castle.ActiveRecord.Framework.Internal.SemanticVerifierVisitor.VisitHasMany(HasManyModel
model) at
Castle.ActiveRecord.Framework.Internal.HasManyModel.Accept(IVisitor
visitor) at
Castle.ActiveRecord.Framework.Internal.AbstractDepthFirstVisitor.VisitNode(IVisitable
visitable) at
Castle.ActiveRecord.Framework.Internal.AbstractDepthFirstVisitor.VisitNodes(IEnumerable
nodes) at
Castle.ActiveRecord.Framework.Internal.AbstractDepthFirstVisitor.VisitModel(ActiveRecordModel
model) at
Castle.ActiveRecord.Framework.Internal.SemanticVerifierVisitor.VisitModel(ActiveRecordModel
model) at
Castle.ActiveRecord.Framework.Internal.ActiveRecordModel.Accept(IVisitor
visitor) at
Castle.ActiveRecord.Framework.Internal.AbstractDepthFirstVisitor.VisitNode(IVisitable
visitable) at
Castle.ActiveRecord.Framework.Internal.AbstractDepthFirstVisitor.VisitNodes(IEnumerable
nodes) at
Castle.ActiveRecord.ActiveRecordStarter.RegisterTypes(ISessionFactoryHolder
holder, IConfigurationSource source, IEnumerable`1 types, Boolean
ignoreProblematicTypes) at
Castle.ActiveRecord.ActiveRecordStarter.Initialize(IConfigurationSource
source, Type[] types) at SAMPLE_1.Program.Main(String[] args) in
E:\C# PROJECTS\STUDY\STUDY.ORM\Active RecordSAMPLE_1.PhotoAlbum
I think problem is here:
[HasMany(Inverse = false,Cascade = ManyRelationCascadeEnum.Delete)]
public IList<PhotoAlbum> Album
{
get { return _albums; }
set { _albums = value; }
}
If I omitted this property / relationship it works good.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
假设一个配置文件有许多相册,您的
PhotoAlbum
类缺少一个属性:Assuming one profile has many photo albums, your
PhotoAlbum
class is missing a property: