Reputation:
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
Upvotes: 0
Views: 1181
Reputation:
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" ...
Upvotes: 1
Reputation: 8357
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.
Upvotes: 0
Reputation: 10764
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?
Upvotes: 0