Page 1 of 1

Specifying association without storage attribute

Posted: Fri 25 Oct 2013 13:45
by DavidF
In LinqConnect for Metro I have a class with 2 one to many associations, Handsets and Buttons:

[Table(Name="Telephone")]
public class Telephone
{
[Column(IsPrimaryKey = true)]
public Guid Id { get; set; }
[Column]
public string Name { get; set; }

private EntitySet<TelephoneButton> _buttons = new EntitySet<TelephoneButton>();
[Association(Storage = "_buttons", OtherKey = "TelephoneId")]
public IEnumerable<TelephoneButton> Buttons
{
get { return this._buttons; }
set { this._buttons.Assign(value); }
}
private EntitySet<TelephoneHandset> _handsets = new EntitySet<TelephoneHandset>();
[Association(Storage = "_handsets", OtherKey = "TelephoneId")]
public IEnumerable<TelephoneHandset> Handsets
{
get { return this._handsets; }
set { this._handsets.Assign(value); }
}
}

This works fine. However, if I remove the storage property on the AssociationAttributes, inserting a Telephone entity gives the following error:

System.ArgumentException occurred
HResult=-2147024809
Message=Property 'System.Collections.Generic.IEnumerable`1[ClassLibrary1.TelephoneHandset] Handsets' is not defined for type 'System.Object'

The error does not occur if there is only one association defined on the class. The reason I need to do this is to allow the use of classes defined in a portable class library which cannot contain properties of type EntitySet<>. Is there any workaround for this?

Re: Specifying association without storage attribute

Posted: Fri 25 Oct 2013 15:34
by DavidF
This is also a problem if the storage member is not defined as EntitySet<> type, e.g. it is defined as List<T>

The problem only occurs when there is more than one one-to-many association on the class.

Re: Specifying association without storage attribute

Posted: Mon 28 Oct 2013 10:16
by MariiaI
Please pay attention to the Fluent mapping approach: http://www.devart.com/linqconnect/docs/ ... pping.html.
According to your scenario, it is the most suitable solution for you (e.g., EntitySet types are not used in the generated classes).

If you have any further questions, feel free to contact us.

Re: Specifying association without storage attribute

Posted: Tue 29 Oct 2013 11:41
by DavidF
Hi,

I've changed my mapping to fluent, however the same error occurs - if there are more than one one-to-many associations on the entity an error occurs on SubmitChanges:

System.ArgumentException occurred
HResult=-2147024809
Message=Property 'System.Collections.Generic.List`1[ClassLibrary1.TelephoneHandset] Handsets' is not defined for type 'System.Object'
Source=System.Core
StackTrace:
at System.Linq.Expressions.Expression.Property(Expression expression, PropertyInfo property)
at Devart.Data.Linq.Mapping.EntityCopyFuncGenerator. (Expression , MetaType )
at Devart.Data.Linq.Mapping.EntityCopyFuncGenerator. (MetaType )
at Devart.Data.Linq.Mapping.EntityCopyFuncGenerator.CreateEntityCopyFunc(MetaType )
at Devart.Data.Linq.Mapping.MetaType.get_CopyFunc()
at Devart.Data.Linq.Mapping.MetaType.Clone(Object )
at Devart.Data.Linq.Engine.ObjectEntry.SetUpdatedState()
at Devart.Data.Linq.Engine.ChangeTracker. (IObjectEntry , MetaDataMember )
at Devart.Data.Linq.Engine.ChangeTracker. (IObjectEntry )
at Devart.Data.Linq.Engine.ChangeTracker. ()
at Devart.Data.Linq.Engine.ChangeTracker. .Commit()
at Devart.Data.Linq.Engine.SubmitCoordinator.Submit(ConflictMode )
at Devart.Data.Linq.DataContext.SubmitChanges(ConflictMode failureMode)
at Devart.Data.Linq.DataContext.SubmitChanges()

Entities:

public class Telephone
{
public Telephone()
{
Buttons = new List<TelephoneButton>();
Handsets = new List<TelephoneHandset>();
}
public Guid Id { get; set; }
public string Name { get; set; }
public List<TelephoneButton> Buttons { get; set; }
public List<TelephoneHandset> Handsets { get; set; }
}

public class TelephoneButton
{
public Guid Id { get; set; }
public Guid TelephoneId { get; set; }
public string Caption { get; set; }
public Telephone Telephone { get; set; }
}

public class TelephoneHandset
{
public Guid Id { get; set; }
public string Name { get; set; }
public Guid TelephoneId { get; set; }
public Telephone Telephone { get; set; }
}

Mapping definition:

builder.Entity<Telephone>().FullTableName(@"""Telephone""").PrimaryKey(t => t.Id);
builder.Entity<Telephone>().Association()
.ToMany(t => t.Buttons)
.ThisKey(t => t.Id)
.FromOne(b => b.Telephone)
.OtherKey(b => b.TelephoneId);

builder.Entity<Telephone>().Association()
.ToMany(t => t.Handsets)
.ThisKey(t => t.Id)
.FromOne(h => h.Telephone)
.OtherKey(h => h.TelephoneId);

builder.Entity<TelephoneHandset>().FullTableName(@"""TelephoneHandset""").PrimaryKey(t => t.Id);
builder.Entity<TelephoneButton>().FullTableName(@"""TelephoneButton""").PrimaryKey(b => b.Id);

Re: Specifying association without storage attribute

Posted: Wed 30 Oct 2013 08:16
by MariiaI
Message=Property 'System.Collections.Generic.List`1[ClassLibrary1.TelephoneHandset] Handsets' is not defined for type 'System.Object'
We couldn't reproduce this issue in our environment. Please send us a test project, with which this issue could be reproduced, so that we are able to investigate it and find the solution for you.

Re: Specifying association without storage attribute

Posted: Thu 31 Oct 2013 09:28
by DavidF
MariiaI wrote: We couldn't reproduce this issue in our environment. Please send us a test project, with which this issue could be reproduced, so that we are able to investigate it and find the solution for you.
Have you managed to reproduce the problem using the project I sent?

Re: Specifying association without storage attribute

Posted: Thu 31 Oct 2013 09:48
by MariiaI
Have you managed to reproduce the problem using the project I sent?
Thank you for the sample project.
We have reproduced this issue. We will investigate it and inform you about the results as any are available.

Re: Specifying association without storage attribute

Posted: Wed 06 Nov 2013 09:17
by DavidF
Have you made any more progress with this issue?

Thanks,

David

Re: Specifying association without storage attribute

Posted: Wed 06 Nov 2013 10:15
by MariiaI
We have fixed this ussue. We will inform you when the corresponding build of LinqConnect for Metro is available for download.

Re: Specifying association without storage attribute

Posted: Thu 14 Nov 2013 12:36
by MariiaI
New build of LinqConnect for Metro 4.4.374 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=28335.