2011-05-17 239 views
5

我已经定义,像这样一类:petapoco插入问题

public class Location 
{ 
    public Location() 
    { 
     Meetings = new List<Meeting>(); 
    } 

    public virtual int ID { get; private set; } 
    public virtual string Name { get; set; } 

    public virtual ICollection<Meeting> Meetings { get; set; } 

} 

而且这个数据库表仅仅是“位置”用一个ID和一个名称属性。

某些其他表“会议”有一个外键返回到此表。这是超出了我试图在这个例子中工作的范围,但我认为这是导致PetaPoco失败...

我想使用PetaPoco插入一个新的位置到数据库中这样:

public int AddLocation(string name) 
    { 
     var newLocation = new Location{Name = name}; 
     var db = new PetaPoco.Database(_connectionString); 
     db.Insert("locations", "ID", newLocation); 
     return newLocation.ID; 
    } 

而且它引发错误像这样:

{“无映射从对象类型 System.Collections.Generic.List`1 [[NHRepoTemplate.sampleUsage.sampleModel.Meeting存在, NHRepoTemplate,Version = 1.0.0.0, 文化=中立,公钥=空] 到已知的托管提供本地 型“}。

在我看来,像孩子收集引起PetaPoco不能够做插件的存在,但是......必须有办法让它“忽略”,对吧?

+0

添加乔恩提到的属性是正确的。然后,会议类应该有一个LocationId属性,您可以使用它返回到此位置 – Schotime 2011-05-19 23:00:46

回答

6

尝试把这个在您的会议性质:

[PetaPoco.Ignore] 
+0

感谢Jon。应该有sen的那个。 – 2011-05-23 10:48:23

0

如果您使用petapoco类以上[ExplicitColumns]属性,所有属性不具备[Column]属性将被忽略