Pregunta

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?

¿Fue útil?

Solución

Try putting this over your Meetings property:

[PetaPoco.Ignore]

Otros consejos

if you use [ExplicitColumns] attribute above your petapoco class, all properties that do not have the [Column] attribute will be ignored

Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top