petapoco插入问题

Tra*_*rde 5 orm 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; }

}
Run Code Online (Sandbox Code Playgroud)

而这个数据库表只是带有ID和Name属性的"位置".

其他一些表"会议"有一个外键回到此表.它是超出了我想在这个例子中与之合作的范围,但我认为这是造成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;
    }
Run Code Online (Sandbox Code Playgroud)

它会抛出这样的错误:

{"对象类型System.Collections.Generic.List`1 [[NHRepoTemplate.sampleUsage.sampleModel.Meeting,NHRepoTemplate,Version = 1.0.0.0,Culture = neutral,PublicKeyToken = null]]不存在映射到已知的托管提供者本机类型."}

在我看来,子集合的存在导致PetaPoco无法进行插入,但是......必须有一种方法告诉它"忽略"那个,对吧?

Jon*_*Jon 6

试着将它放在Meetings属性上:

[PetaPoco.Ignore]
Run Code Online (Sandbox Code Playgroud)