I have a class defined like so:
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; }
}
And the database table for this is just “locations” with an ID and a Name property.
Some other table “meetings” has a foreign key back to this table. And it is beyond the scope of what I’m trying to work with in this example, yet I think it is causing PetaPoco to fail…
I’m trying to use PetaPoco to insert a new location into the database like this:
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;
}
And it is throwing an error like so:
{"No mapping exists from object type System.Collections.Generic.List`1[[NHRepoTemplate.sampleUsage.sampleModel.Meeting, NHRepoTemplate, Version=1.0.0.0, Culture=neutral, PublicKeyToken=nul开发者_开发知识库l]] to a known managed provider native type."}
It seems to me like the existence of the child collection causes PetaPoco to not be able to do the insert, but... there must be a way to tell it to "ignore" that, right?
Try putting this over your Meetings property:
[PetaPoco.Ignore]
if you use [ExplicitColumns]
attribute above your petapoco class, all properties that do not have the [Column]
attribute will be ignored
精彩评论