fluent inheritance

fluent inheritance

Postby unclelem » Wed 19 Aug 2015 17:30

I have an issue with fluent inheritance (Table per hierarchy) where inserting a subtype only stores the subtype fields, and none of the root class fields.

Code: Select all
    public class Thing
    {
        public Thing()
        {
            DV = "A";
        }

        public string Id { set; get; }
        public string Property1 { set; get; }
        public string DV { set; get; }
    }


    public class AThing : Thing
    {
        public AThing():base()
        {
            DV = "A";
        }

        public string P2 { set; get; }
    }


and fluent mapping
Code: Select all
       builder.Entity<Thing>()
            .FullTableName("THING_TABLE")
            .PrimaryKey(p => p.Id);
        // Table Per Hierarchy (TPH) inheritance:
        builder.Entity<Thing>()
            .Map().Discriminator(p => p.DV)
            .DiscriminatorValue("R")
            .IsInheritanceDefault()
            .MapChild<AThing>()
            .DiscriminatorValue("A")
            ;
        // Properties:
        builder.Entity<Thing>()
            .Property(p => p.Id)
            .ServerDataType("varchar(40)")
            .ColumnName("Id");
        builder.Entity<Thing>()
            .Property(p => p.Property1)
            .ServerDataType("varchar(40)")
                .ColumnName("Property1");
        builder.Entity<Thing>()
            .Property(p => p.DV)
            .ServerDataType("varchar(1)")
            .ColumnName("Dv");

        builder.Entity<AThing>().Property(p => p.P2).ColumnName("P2");


If I insert a Thing, I get all properties set in the table (except for P2 - which is correct for a root object).

If I insert an AThing, *only* the P2 column is set, all other rows are unset (default value or null).

The log console clearly shows that only the derived properties are being set
Code: Select all
INSERT INTO THING_TABLE (P2) VALUES (:p1)
-- p1: Input VarChar (Size = 10; DbType = AnsiString) [some stuff]


Am I missing something, or is this a bug?
Thanks
unclelem
 
Posts: 6
Joined: Tue 11 Aug 2015 17:01

Re: fluent inheritance

Postby MariiaI » Thu 20 Aug 2015 08:32

Thank you for the report on this. We have reproduced this issue. We will investigate it more clearly and inform you about the results as soon as possible.
MariiaI
Devart Team
 
Posts: 1472
Joined: Mon 13 Feb 2012 08:17

Re: fluent inheritance

Postby MariiaI » Fri 18 Sep 2015 05:20

The bug related to working with TPH inheritances and fluent mapping approach is fixed.

New build of LinqConnect 4.5.835 is available for download now!
It can be downloaded from http://www.devart.com/linqconnect/download.html (trial version) or from Registered Users' Area (for users with active subscription only).

For more information, please refer to http://forums.devart.com/viewtopic.php?f=31&t=32490.
MariiaI
Devart Team
 
Posts: 1472
Joined: Mon 13 Feb 2012 08:17


Return to LinqConnect (LINQ to SQL support)