LLBLGen Pro v3.1 Final
Hi, I am using WebApi to get data using LLBL and sending the entities back to JSON.
Saw this blog post and followed the instructions here:
http://weblogs.asp.net/fbouma/how-to-make-asp-net-webapi-serialize-your-llblgen-pro-entities-to-json
However I am encountering a problem in which some entities fail to serialize and I see data coming back from the JSON call. Upon further inspection I noticed it happens when I have an entity (A) referencing another entity (B) which references back to EntityCollection<A>, and has more than one item in the collection.
For example:
I have an EntityCollection<Shoes>. Each Shoe references a Brand entity. Inside the Brand entity LLBL generated a EntityCollection<Shoes> which points back to the root entity. If I have multiple shoes of the same brand then only one result will serialize back correctly.
Looking in the generated code I see the [DataMember] attribute created for the collection.
[TypeContainedAttribute(typeof(ItemEntity))]
[DataMember]
public virtual EntityCollection<ItemEntity> Items
{
get { return GetOrCreateEntityCollection<ItemEntity, ItemEntityFactory>("ProductLine", true, false, ref _items); }
}
If I remove the DataMember then I am able to serialize properly. It seems that the two-way referencing is the culprit.
Since the code was generated using the designer I shouldn't really go in and change this every time. Is there any way to fix this (designer or code) so it doesn't generate DataMember attributes for these loopbacks? I can't remove this completely from NavigatorCollection because I still need it for some entity relationships.
Thanks,
Gilbert