WriteXml incorrectly serializes not persisted entity in LLBLGen 2.6

Posts   
 
    
Robert.W
User
Posts: 79
Joined: 19-Jun-2007
# Posted on: 08-Apr-2013 16:26:50   

Hi,

I'm using LLBLGen 2.6.11.0427 Code generated with adapter templates

I have something like this:

[Serializable] [DataContract] public class Currency { [DataMember] public string Code { get; protected set; }

    [DataMember]
    public string Name { get; protected set; }

    protected Currency()
    {

    }

    public Currency(string code, string name)
    {
        Code = code;
        Name = name;
    }
}

public partial class LLBLGenGeneratedEntity { public Currency Currency {get;set;} }

When I do :

var x = new LLBLGenGeneratedEntity() { Currency = new Currency("A", "A")}; string xml = null; x.WriteXml(XmlFormatAspect.Compact25, out xml); var clone = new LLBLGenGeneratedEntity(); clone.ReadXml(xml);

I get:

System.ArgumentException : Object of type 'System.String' cannot be converted to type Namespace.Currency'.

This because LLBLGen serialies the Currency as:

<Currency>Namespace.Currency</Currency>

It does however work when I first persist the entity and then load it. How do I make LLBLGen correctly serialize entities that were not previously persisted .

Regards, Robert.

Walaa avatar
Walaa
Support Team
Posts: 14950
Joined: 21-Aug-2005
# Posted on: 08-Apr-2013 20:39:44   

You should use Custom Member Serialization.