none
Map inheritance from generic class RRS feed

  • Question

  • 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

    Saturday, February 28, 2009 12:30 PM

Answers

  • I found the answer myself, after I looked into IL of my generic class. In IL its name looks like SimpleStage`1<...> so the issue with mapping file was fixed when I wrote

    <Type Name="BusinessLogic.Domain.SimpleStage`1" ...
    Saturday, February 28, 2009 3:16 PM