wcf 客户端代理生成的类中缺少数据成员顺序

发布于 2024-09-19 22:14:46 字数 1361 浏览 5 评论 0原文

已将表从 sql 数据库映射到 Employee dbml 文件中的 linq。

[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;
            }
        }
    }

}

在服务中,当我在客户端中添加服务引用时,我只是返回类型的对象,

List<tbEmployee>

跳过日期会员订单信息。

由于我使用 protobuf-net 进行序列化/反序列化,因此出现了问题 在我的客户端反序列化时。

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.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

绝不放开 2024-09-26 22:14:46

是的,这很麻烦。有 2 个选项可以解决此问题;第一个(也是最简单的)是使用 WCF 的能力在客户端和服务器之间共享契约程序集。如果您可以共享 DTO 层,那么事情就会变得简单。

第二个是在客户端添加额外的标记以提供线索。您可以通过 partial 类来完成此操作,例如在单独的代码文件中(不要编辑生成的文件):

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

更明确的替代方案是:

namespace YourNamespace {
    [ProtoPartialMember(1, "EmployeeID")]
    [ProtoPartialMember(2, "EmployeeName")]
    public partial class tbEmployee {}
}

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 {}
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文