This is a migrated thread and some comments may be shown as answers.

Adding multiple Vertical Inheritance Entities

1 Answer 50 Views
Development (API, general questions)
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
Pedro
Top achievements
Rank 1
Pedro asked on 29 Jun 2012, 08:06 PM
Hello,

I've been struggling around with an example throwing me a strange error. Here's the scenario I'm working on:

Classes
public abstract class A
{
    public Int32 Id { get; set; }
    public String Name { get; set; }
    public IList<D> Ds { get; set; }
}
 
public class B : A
{
    public String Description { get; set; }
 
    public B()
    {
        Ds = new List<D>();
    }
}
 
public class C : A
{
    public Int32 Value { get; set; }
 
    public C()
    {
        Ds = new List<D>();
    }
}
 
public class D
{
    public Int32 Id { get; set; }
    public String Name { get; set; }
    public IList<A> As { get; set; }
 
    public D()
    {
        As = new List<A>();
    }
}

Fluent Mapping
List<MappingConfiguration> configurations = new List<MappingConfiguration>();
 
MappingConfiguration<A> A = new MappingConfiguration<FluentModel1.A>();
A.MapType(x => new
{
    id = x.Id,
    name = x.Name
}).ToTable("ATable");
A.HasProperty(x => x.Id).IsIdentity(KeyGenerator.Autoinc);
 
MappingConfiguration<B> B = new MappingConfiguration<FluentModel1.B>();
B.MapType(x => new
{
    description = x.Description
}).Inheritance(Telerik.OpenAccess.InheritanceStrategy.Vertical).ToTable("BTable");
 
MappingConfiguration<C> C = new MappingConfiguration<FluentModel1.C>();
C.MapType(x => new
{
    value = x.Value
}).Inheritance(Telerik.OpenAccess.InheritanceStrategy.Vertical).ToTable("CTable");
 
MappingConfiguration<D> D = new MappingConfiguration<FluentModel1.D>();
D.MapType(x => new
{
    id = x.Id,
    name = x.Name
}).ToTable("DTable");
D.HasProperty(x => x.Id).IsIdentity(KeyGenerator.Autoinc);
 
//D.HasAssociation<A>(x => x.As).IsDependent().IsManaged().WithOpposite(x => x.Ds).MapJoinTable("AxD", (x, y) => new { IdA = x.Id, IdD = y.Id });
//A.HasAssociation<D>(x => x.Ds).IsDependent().IsManaged().WithOpposite(x => x.As);
 
configurations.Add(A);
configurations.Add(B);
configurations.Add(C);
configurations.Add(D);

(The associations have been commented out to better isolate the issue)

Test Code:
using (var aContext = new FluentModel1Context())
{
    B b1 = new B();
    //b1.Id = 99;
    b1.Name = "First";
    b1.Description = "Desc1";
 
    B b2 = new B();
    //b2.Id = 98;
    b2.Name = "Second";
    b2.Description = "Desc2";
 
    aContext.Add(b1);
    aContext.Add(b2);
 
    aContext.SaveChanges();
}

In the scenario above, the "aContext.SaveChanges()" line will throw me the following exception: "Insert of '1023727798-2' failed: Telerik.OpenAccess.RT.sql.SQLException: Previous result set was not closed."

Further testing has shown me that the exception will not be thrown in any of the following cases:
  • If I change the A.Id identity mapping to "A.HasProperty(x => x.Id).IsIdentity();" removing the autoinc and manually handle id fields (note the commented lines on the "test code").
  • If I change the A.Id identity mapping to "A.HasProperty(x => x.Id).IsIdentity(KeyGenerator.Guid);" removing the autoinc and handling id generation with guid.
  • If I work with autoinc but in a non-inheritance entity, such as D from this example
  • If I add a "aContext.SaveChanges()" between "aContext.Add(b1)" and "aContext.Add(b2)" thus performing single operation inserts

It seems tome the behavior is somewhere between the workings of autoinc with inheritance, but only on multiple inserts. Is it expected? Is it a bug? Is my code screwed up somehow?

Thanks in advance.

Regards,

Pedro

1 Answer, 1 is accepted

Sort by
0
Zoran
Telerik team
answered on 04 Jul 2012, 01:53 PM
Hi Pedro,

 We did fix a bug in our product, resulting in the same error for the Service Pack 1 of the Q2 2012 version of OpenAccess. This Service Pack was released last week. Can you confirm if you are actually using that version of our product, or you use an earlier one like the official Q2 release? If you are using an earlier version, please try updating to the latest one and test if the error is still there.

Greetings,
Zoran
the Telerik team
OpenAccess ORM Q2'12 Now Available! Get your hands on all the new stuff.
Tags
Development (API, general questions)
Asked by
Pedro
Top achievements
Rank 1
Answers by
Zoran
Telerik team
Share this question
or