I am trying to find a way to get POCOs to work with Linq-to-Sql when my domain model is not controlled by a table - this means that my domain objects do not match the database schema.
For example, at my domain level, I have an Appointment object that has a Recurrence property of type Recurrence. This is a base class with several subclasses, each based on a specific repetition pattern.
In my database, it makes no sense to have a separate AppointmentRecurrences table, when there is always a one-to-one relationship between the appointment record and its repetition. Thus, the Assignments table contains the columns RecurrenceType and RecurrenceValue. RecurrenceType has a foreign key relationship to the RecurrenceTypes table because there is a one-to-many relationship between the repeat type (pattern) and the Destination table.
If there is a way to create the correct mapping between the two models in Linq-to-Sql, I remain with the manual resolution of the impedance mismatch in the code.
This gets even more complicated when it comes to querying the database using the Specification template. For example, if I want to return a list of current assignments, I can easily create a Specification object that uses the following expression: appt => appt.Recurrence.IsDue . However, this does not translate into Linq-to-SQL space, because the original expression type is not the one that recognizes L2S (for example, it is not an L2S object).
So, how can I create complex mapping in Linq-to-SQL to support my domain model?
Or is there a better way to implement a specification template in this case? I was thinking about using interfaces that will be implemented by both my domain object and the L2S object (through partial ones), but this is impossible with the impedance mismatch between the two object graphs.
Suggestions?
source share