Inheritance problems
Posted: Sat 10 Apr 2010 01:16
Hi there,
I have three classes derived from each other (Subject->Person->PrivatePerson). The root Subject class is abstract, the other classes have discriminator inheritance codes set to 1(Person) and 2 (PrivatePerson). The discriminator column is of type integer (NUMBER(10) is database).
First problem:
When I try to read data from Subject entity like this:
I get the following exception:
I want to select only Persons instances.
Variant A)
Doesn't compile, because no Persons table property generated in data context.
Variant B)
Crash with exception:
Crash with exception from the very first problem.
Any help?
I have three classes derived from each other (Subject->Person->PrivatePerson). The root Subject class is abstract, the other classes have discriminator inheritance codes set to 1(Person) and 2 (PrivatePerson). The discriminator column is of type integer (NUMBER(10) is database).
First problem:
When I try to read data from Subject entity like this:
Code: Select all
var subjects = ctx.Subjects.ToList();
Very meaningful obfuscated callstack:The binary operator Equal is not defined for the types 'System.Int32' and 'System.Object'.
Second problem:at System.Linq.Expressions.Expression.GetEqualityComparisonOperator(ExpressionType binaryType, String opName, Expression left, Expression right, Boolean liftToNull)
at System.Linq.Expressions.Expression.Equal(Expression left, Expression right)
at Devart.Data.Linq.Provider.SelectionBuilder.a(bk A_0)
at Devart.Data.Linq.Provider.SelectionBuilder.a(SqlExpression A_0)
at Devart.Data.Linq.Provider.SelectionBuilder.BuildSelection(SqlExpression selection)
at Devart.Data.Linq.Provider.j.a(n A_0, SqlExpression A_1)
at Devart.Data.Linq.Provider.j.a(Type A_0, SqlExpression A_1, n A_2, Type A_3, Type A_4)
at Devart.Data.Linq.Provider.DataProvider.b.a(List`1 A_0, n A_1, SqlNode A_2)
at Devart.Data.Linq.Provider.DataProvider.b..ctor(a A_0, n A_1)
at Devart.Data.Linq.Provider.DataProvider.a(Expression A_0)
at Devart.Data.Linq.Provider.DataProvider.i(Expression A_0)
at Devart.Data.Linq.DataQuery`1.i()
at System.Collections.Generic.List`1..ctor(IEnumerable`1 collection)
at System.Linq.Enumerable.ToList[TSource](IEnumerable`1 source)
at Nitro.Dal.Program.Main(String[] args) in d:\tests\DevartProbe\DevartProbe\Program.cs:line 51
I want to select only Persons instances.
Variant A)
Code: Select all
var persons = ctx.Persons.ToList();
Variant B)
Code: Select all
var persons = ctx.GetTable().ToList();
Variant C)Could not retrieve a Table for inheritance subtype 'Person', try Table of Subject instead.
Code: Select all
var persons = ctx.Subjects.OfType().ToList();
Any help?