Simulating multiple table inheritance in Linq-to-SQL

Currently, everyone knows that Linq-to-SQL does not support multiple table inheritance (aka, table-per-subtype) and that you can use other ORM structures such as Entity Framework, NHibernate, etc., instead, if you need built-in support for multiple table inheritance (if you have any doubts, refer to the SO Multiple Inheritance question in LINQtoSQL ).

However, assuming you wanted to use (or were limited to) Linq-to-SQL as your ORM level, did someone define a simple and straightforward design strategy to model multiple inheritance of tables in Linq-to-SQL so that client-side code could be written against the Linq-to-SQL level using a natural object-oriented API?

+5
source share
1 answer

I think Sam got a good answer: Linq2Sql seems to be unable to do this. But for now, you just want to simulate this behavior, I would do something like this:

      /// <summary>
    /// Declare POCO (Plain Old CLR Object) as you would to manipulate your inheritance
    /// </summary>
    public class Person
    {
        public abstract void Load();
        public abstract void Save();
    }

    /// <summary>
    /// Simulate a consistent behavior
    /// </summary>
    public class Customer : Person
    {

        public override void Load()
        {
            // - Do some Linq2Sql stuff
        }

        public override void Save()
        {
            // - Do some Linq2Sql stuff
        }

    }

, "JOIN", , , "Left Outer Join" , hajirazin, "" Person "" .

, . , .

,

0

All Articles