Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

petapoco insert problem

Tags:

orm

petapoco

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=null]] 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?

like image 942
Travis Laborde Avatar asked May 17 '11 21:05

Travis Laborde


1 Answers

Try putting this over your Meetings property:

[PetaPoco.Ignore]
like image 61
Jon Avatar answered Nov 17 '22 00:11

Jon