tags:

views:

36

answers:

1

Hello,

Have mapped table from sql database to linq in Employee dbml file.

[global::System.Runtime.Serialization.DataContractAttribute()]
public partial class tbEmployee
{

    private int _Employeeid;

    private string _EmployeeName;



    public tbEmployee()
    {
    }

    [global::System.Data.Linq.Mapping.ColumnAttribute(Storage = "_Employeeid", DbType = "Int NOT NULL")]
    [global::System.Runtime.Serialization.DataMemberAttribute(Order = 0)]
    public int EmployeeID
    {
        get
        {
            return this._PeriodContextRefId;
        }
        set
        {
            if ((this._Employeeid != value))
            {
                this._Employeeid = value;
            }
        }
    }

    [global::System.Data.Linq.Mapping.ColumnAttribute(Storage = "_EmployeeName", DbType = "NVarChar(2) NOT NULL", CanBeNull = false)]
    [global::System.Runtime.Serialization.DataMemberAttribute(Order = 1)]
    public string EmployeeName
    {
        get
        {
            return this._EmployeeName;
        }
        set
        {
            if ((this._EmployeeName != value))
            {
                this._EmployeeName = value;
            }
        }
    }

}

and in Service i am just returning the object of type

List<tbEmployee>

when i add the service reference in my client the date member order information is skipping.

as i am using the protobuf-net for serialization/deserialization it is giving the problem while deserializing at my client side.

A: 

Yes, that is a nuisance. There are 2 options for fixing this; the first (and easiest) is to use WCF's ability to share a contract assembly between client and server. If you can share the DTO layer, that'll keep things simple.

The second is to add additional markers at the client to give it a clue. You can do this via a partial class, for example in a separate code file (don't edit the generated file):

namespace YourNamespace {
    [ProtoContract(DataMemberOffset = 1)] /* shift all DataMember orders */
    public partial class tbEmployee {}
}

a more explicit alternative is:

namespace YourNamespace {
    [ProtoPartialMember(1, "EmployeeID")]
    [ProtoPartialMember(2, "EmployeeName")]
    public partial class tbEmployee {}
}
Marc Gravell
Thanks marc for the responce. actually i ma having lots of object like this. Basically i am serializing and then compressing it to the byte array and then sending at the silverlight client side. as you suggested the first option means you want me to share the dbml designer class at the client side (DTO trasnfer object) if it can you please give me some examples as i am not aware of this techinique.
Rakesh K
Ah, if you have different platforms at client/server (i.e. Silverlight), then sharing the assembly might not be an option. But sharing the *class file* probably *is* an option...? then your WCF just exposes the byte[] API and there is no code-gen class? This is not a good option, however, if the server code is also generated, for example by LINQ-to-SQL
Marc Gravell