Map inheritance from generic class in Linq To SQL
        Posted  
        
            by Ksenia Mukhortova
        on Stack Overflow
        
        See other posts from Stack Overflow
        
            or by Ksenia Mukhortova
        
        
        
        Published on 2009-02-28T10:10:45Z
        Indexed on 
            2010/05/28
            12:01 UTC
        
        
        Read the original article
        Hit count: 256
        
Hi everyone,
I'm trying to map my inheritance hierarchy to DB using Linq to SQL: Inheritance is like this, classes are POCO, without any LINQ to SQL attributes:
public interface IStage
{ ... }
public abstract class SimpleStage<T> : IStage where T : Process
{ ... }
public class ConcreteStage : SimpleStage<ConcreteProcess>
{ ... }
Here is the mapping:
<Database Name="NNN" xmlns="http://schemas.microsoft.com/linqtosql/mapping/2007">
  <Table Name="dbo.Stage" Member="Stage">
    <Type Name="BusinessLogic.Domain.IStage">
      <Column Name="ID" Member="ID" DbType="Int NOT NULL IDENTITY" IsPrimaryKey="true" IsDbGenerated="true" AutoSync="OnInsert" />
      <Column Name="StageType" Member="StageType" IsDiscriminator="true" />
      <Type Name="BusinessLogic.Domain.SimpleStage" IsInheritanceDefault="true">
        <Type Name="BusinessLogic.Domain.ConcreteStage" IsInheritanceDefault="true" InheritanceCode="1"/>
      </Type>
    </Type>
  </Table>
</Database>
In the runtime I get error: System.InvalidOperationException was unhandled Message="Mapping Problem: Cannot find runtime type for type mapping 'BusinessLogic.Domain.SimpleStage'."
Neither specifying SimpleStage, nor SimpleStage<T> in mapping file helps - runtime keeps producing different types of errors.
DC is created like this:
StreamReader sr = new StreamReader(@"MappingFile.map");
XmlMappingSource mapping = XmlMappingSource.FromStream(sr.BaseStream);
DataContext dc = new DataContext(@"connection string", mapping);
If Linq to SQL doesn't support this, could you, please, advise some other ORM, which does. Thanks in advance,
Regards!
Ksenia
© Stack Overflow or respective owner