Page 1 of 1

Fluent mapping FromMany with no parameters

Posted: Mon 28 Oct 2013 16:47
by DavidF
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);

Re: Fluent mapping FromMany with no parameters

Posted: Wed 30 Oct 2013 08:15
by MariiaI
Thank you for the report. We have reproduced the NullReferenceException with such scenario. We will inform you when it is fixed.

Re: Fluent mapping FromMany with no parameters

Posted: Fri 01 Nov 2013 06:40
by MariiaI
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.

Re: Fluent mapping FromMany with no parameters

Posted: Fri 01 Nov 2013 09:16
by DavidF
Thanks, that works now.