views:

675

answers:

3

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"&gt;
  <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

A: 

Have you added the reference to the files and also are you importing the references with using statements? OR using the fully qualified class names?

REA_ANDREW
sorry, I didn't quite understand, what references you talk about?if you mean decorating my classes with LINQ related attributes, then no, I use POCO classes and only provide mapping in XML file
Sorry I mean Project->Add Reference then selecting the assembly for BusinessLogic.Domain.IStageAlso are you importing the library like using BusinessLogic.Domain;
REA_ANDREW
oh, of course I add the reference to BL assembly and all necessary usings
BTW, without this inheritance hierarchy mapping of other non-inheritant entities works correctly
A: 

I think it's because of the generic type T in SimpleStage: it can't produce internally a mapping lookup table for SimpleStage as T is generic.

Frans Bouma
yes, I also think its because of generic. but I was wondering if there is a way to perform mapping somehow, maybe using other ORM
A: 

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" ...