zoukankan      html  css  js  c++  java
  • 光脚丫学LINQ(026):如何使实体可序列化

    视频演示:http://u.115.com/file/f274c53ada

    光脚重点总结
    要想使对象模型中的实体类对象可被序列化,就应该在实体类的定义中使用DataContractAttribute属性修饰,以及在实体类的列成员中使用DataMemberAttribute属性修饰就可以了。比如下面的代码:

    [Table(Name="dbo.Customers")]   
    [DataContract()]   
    public partial class Customers   
    {    
     [Column(Storage="_CustomerID")]   
     [DataMember(Order=1)]   
     public string CustomerID   
     {   
      get{ return this._CustomerID; }   
      set{ this._CustomerID = value; }   
     }   
    }  
    [Table(Name="dbo.Customers")]
    [DataContract()]
    public partial class Customers
    { 
     [Column(Storage="_CustomerID")]
     [DataMember(Order=1)]
     public string CustomerID
     {
      get{ return this._CustomerID; }
      set{ this._CustomerID = value; }
     }
    }
    


    上面的这个实体类对象就可以被序列化。
    要向对实体类做这样的修改,除了使用手动的方式以外,还可以借助SQLMetal和对象关系设计器这样工具。
    可以使用如下的SQLMetal命令来创建可被序列化的实体类。

    SqlMetal /code:"C:\Northwind.cs" /language:csharp "C:\LINQ\Northwind.mdf" /serialization:unidirectional
    


    上面这个命令决定实体类对象是否可序列化的参数是 /serialization:unidirectional
    至于对象关系设计器,则可以设置【序列化模式】设置为单向来实现这点。

  • 相关阅读:
    归并排序
    快速排序
    UNION与UNION ALL的区别
    聚集索引和非聚集索引
    设计模式之抽象工厂模式
    list中map 的value值时间排序
    webmvc 拦截器 允许跨域 跨域问题 sessionid不一样
    redis 主从复制 和集群
    maven打包
    bcprov-jdk15on包用于创建CSR(证书请求)
  • 原文地址:https://www.cnblogs.com/GJYSK/p/1866331.html
Copyright © 2011-2022 走看看