none
Doesn't LINQ support inherited entity mapping? RRS feed

  • Question

  • I have several tables with same schemas except table name. So I want to be able to use base class like below:

        public class ForumBase 
        { 
            [Column] 
            public int Id { getset; } 
     
            [Column] 
            public string Title { getset; } 
        } 
     
        [Table(Name = "dbo.NewsForum")] 
        public class NewsForum: ForumBase 
        { 
        } 
     
        class Program 
        { 
            static void Main(string[] args) 
            { 
                using (DataContext context = new DataContext("Data Source=.\\SQLEXPRESS;AttachDbFilename=|DataDirectory|\\Database.mdf;Integrated Security=True;User Instance=True")) 
                { 
                    var entity = context.GetTable<NewsForum>().FirstOrDefault(); 
     
                    Console.WriteLine(entity.Id); 
                } 
            } 
        } 


    However, I get exception saying,

    'Data member 'Int32 Id' of type 'ForumBase' is not part of the mapping for type 'NewsForum'. Is the member above the root of an inheritance hierarchy?'


    Monday, December 15, 2008 2:32 PM