I have these classes:
class Car {
int ID;
string Name;
}
class Truck : Car {
int MaximumLoad;
}
I have these tables
Car
- ID
- Name
Truck
- CarID
- MaximumLoad
How could I map my classes with my table using PetaPoco ?
I have these classes:
class Car {
int ID;
string Name;
}
class Truck : Car {
int MaximumLoad;
}
I have these tables
Car
- ID
- Name
Truck
- CarID
- MaximumLoad
How could I map my classes with my table using PetaPoco ?
To read truck records I would create a Trucks view that combines the two tables. Or have a look at Schotime's muliple result sets :
http://schotime.net/blog/index.php/2011/11/20/petapoco-multiple-result-sets/
For writes I guess you are asking "how can I write to 2 tables in one operation". Off the top of my head I would probably say I would simply perform 2 writes. I think Petapoco will ignore fields that don't map so you may be able to use your truck object for both writes.
Could easily be wrong as I haven't tested this.
I think (have not tested though) that if you do something like this..
or
I would probably have called my base class vehicle rather than car, buts that's just me.
Hope that helps ?
If you store Car and Truck in the same table (TPH) you can inherit Truck from Car with minor changes to PetaPOCO source code,
table Vehicle (ID, Discriminator, Name, MaximumLoad)
in PetaPOCO.cs, add
Then in your Car.cs and Truck.cs, you can write/generate code like this,