Fluent mapping FromMany with no parameters

Discussion of open issues, suggestions and bugs regarding LinqConnect – Devart's LINQ to SQL compatible ORM
Post Reply
DavidF
Posts: 18
Joined: Fri 11 Oct 2013 10:07

Fluent mapping FromMany with no parameters

Post by DavidF » Mon 28 Oct 2013 16:47

I'm having trouble mapping a one to many association where only the "one" end contains a navigation property.

e.g. I have 2 entities, Customer and CustomerCat
Customer has CustomerCat property but CustomerCat does not have a Customers property

I can specify the following mapping:

builder.Entity<Customer>()
.Association()
.ToOne(customer => customer.CustomerCat)
.ThisKey(customer => customer.CustomerCatId)
.FromMany().OtherKey(cat => cat.Id);

But I get the following error on creating the DataContext:

System.NullReferenceException occurred
HResult=-2147467261
Message=Object reference not set to an instance of an object.
Source=Devart.Data.Linq
StackTrace:
at Devart.Data.Linq.Mapping.Fluent.FluentMappingValidator.CheckAssociationConfiguration(IAssociationConfiguration , IModelConfiguration )
at Devart.Data.Linq.Mapping.Fluent.SetAssociationOtherSideConvention.Apply(IEntityConfiguration configuration, IModelConfiguration modelConfiguration)
at Devart.Data.Linq.Mapping.Fluent.EntityConvention.Apply(IClassConfiguration configuration, IModelConfiguration modelConfiguration)
at Devart.Data.Linq.Mapping.Fluent.FluentMappingSource. (ModelMappingConfiguration , Type )
at Devart.Data.Linq.Mapping.Fluent.FluentMappingSource.CreateMetaDataLoader(MetaModel , Type )
at Devart.Data.Linq.Mapping.MappingSource. (Type )
at Devart.Data.Linq.Mapping.MappingSource.GetModel(Type dataContextType)
at Devart.Data.Linq.DataContext. (Object , MappingSource , Type )
at Devart.Data.Linq.DataContext..ctor(String connectionString, MappingSource mapping)


If I add the Customers property to CustomerCat it works

builder.Entity<Customer>()
.Association()
.ToOne(customer => customer.CustomerCat)
.ThisKey(customer => customer.CustomerCatId)
.FromMany(cat => cat.Customers).OtherKey(cat => cat.Id);

MariiaI
Devart Team
Posts: 1472
Joined: Mon 13 Feb 2012 08:17

Re: Fluent mapping FromMany with no parameters

Post by MariiaI » Wed 30 Oct 2013 08:15

Thank you for the report. We have reproduced the NullReferenceException with such scenario. We will inform you when it is fixed.

MariiaI
Devart Team
Posts: 1472
Joined: Mon 13 Feb 2012 08:17

Re: Fluent mapping FromMany with no parameters

Post by MariiaI » Fri 01 Nov 2013 06:40

MariiaI wrote:Thank you for the report. We have reproduced the NullReferenceException with such scenario. We will inform you when it is fixed.
Please try the new build of LinqConnect 4.4.364!
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=28242.

DavidF
Posts: 18
Joined: Fri 11 Oct 2013 10:07

Re: Fluent mapping FromMany with no parameters

Post by DavidF » Fri 01 Nov 2013 09:16

Thanks, that works now.

Post Reply