Reputation: 37
I am using dapper extension methods like insert for everything related to the database in a project but I am not able to connect the models to each other. There are 4 tables in the database: category, event, speaker, and eventspeaker (pivot table). Is there a way to do it like using classmappings in NHibernate? Or do I have to change all foreign keys to int and do everything in the Save, update, etc.. methods?
public class Event
{
public int Id {get; set;}
public Category Category {get;set;}
public string Location {get;set;}
public DateTime Time {get;set;}
public void Save(){ /*TODO*/}
}
public class Category
{
public int Id {get; set;}
public string Category {get;set;}
public void Save(){ /*TODO*/}
}
public class Speaker
{
public int Id {get; set;}
public string Name {get;set;}
public void Save(){ /*TODO*/}
}
public class EventSpeaker
{
public Event event {get; set;}
public Speaker Speaker {get;set;}
}
Upvotes: -1
Views: 806
Reputation: 37
There is no solution for pivot tables yet in DapperExtensions.
Foreign keys should be stored as integers. If say a category instance is required for each event, then a non-mapped category instance can also be added.
A class should also be added for each pivot table.
Upvotes: 0