linq.designer.cs学习笔记

#pragma warning disable 1591

去除1591的警告信息

 

[System.Data.Linq.Mapping.DatabaseAttribute(Name="Development")]

设置linq连接的数据库为"Development"

 

public partial class LinQDBDataContext : System.Data.Linq.DataContext

partial这是声明分部类的一个关键字,为C#2.0中新增的, 一个类可以分成很多部分,写在不同的地方

继承了Linq.DataContext类,主要实现对数据库对象访问的方法

 

private static System.Data.Linq.Mapping.MappingSource mappingSource = new AttributeMappingSource();

定义私有静态变量mappingSource,绑定为前面定义的DatabaseAttribute(Name=" ")

 

#region Extensibility Method Definitions

#endregion

#region C# 预处理器指令。

#region 是一个分块预处理命令,它主要是用于编辑器代码的分块,在编译时会被自动删除。

#region 使您可以在使用 Visual Studio 代码编辑器的大纲显示功能时指定可展开或折叠的代码块。

 

public LinQDBDataContext():base(global::System.Configuration.ConfigurationManager.ConnectionStrings["DevelopmentConnectionString"].ConnectionString, mappingSource)

base的作用://子类的构造函数继承的为父类第几个构造函数(这里继承自含有2个参数的DataContext的构造函数)

这个构造函数通过读取web.config中的connectionStrings来生成LinQDBDataContext对象

linq会自动在web.config中生成对数据库的配置项

<connectionStrings>

  <add name="DevelopmentConnectionString" connectionString="Data Source=CC-0264C27A02CC\SQLEXPRESS;Initial Catalog=Development;Integrated Security=True"

   providerName="System.Data.SqlClient" />

 </connectionStrings>

 

public LinQDBDataContext(string connection) : base(connection, mappingSource)

这个构造函数通过自定义connection来生成LinQDBDataContext对象

 

public LinQDBDataContext(System.Data.IDbConnection connection) : base(connection,mappingSource)

这个构造函数根据IDbConnection接口中定义的connection来生成LinQDBDataContext对象

 

public LinQDBDataContext(string connection, System.Data.Linq.Mapping.MappingSource mappingSource) : base(connection, mappingSource)

这个构造函数可以自定义connectionmappingSource

 

public LinQDBDataContext(System.Data.IDbConnection connection, System.Data.Linq.Mapping.MappingSource mappingSource) : base(connection, mappingSource)

这个构造函数根据IDbConnection接口中定义的connection和自定义的mappingSource来生成LinQDBDataContext对象

 

public System.Data.Linq.Table<ModuleTable> ModuleTable

     {

         get

         {

              return this.GetTable<ModuleTable>();

         }

     }

根据用户在数据库中创建的表自动生成,返回一个表对象的泛型集合

 

[Table(Name="dbo.ModuleTable")]

自动生成对每个表的对象

 

public partial class ModuleTable : INotifyPropertyChanging, INotifyPropertyChanged

INotifyPropertyChanging 是在 .NET Framework 3.5 版中引進的

INotifyPropertyChanging 介面是用來告知用戶端 (通常是繫結用戶端),屬性值正在變更。

 

private static PropertyChangingEventArgs emptyChangingEventArgs = new PropertyChangingEventArgs(String.Empty);

定义属性值变化对象

 

[Column(Storage="_ModuleName", DbType="VarChar(50) NOT NULL", CanBeNull=false)]

     public string ModuleName

     {

         get

         {

              return this._ModuleName;

         }

         set

         {

              if ((this._ModuleName != value))

              {

                   this.OnModuleNameChanging(value);

                   this.SendPropertyChanging();

                   this._ModuleName = value;

                   this.SendPropertyChanged("ModuleName");

                   this.OnModuleNameChanged();

              }

         }

     }

绑定每列的属性,setget方法

 

#pragma warning restore 1591

恢复1591的警告信息

posted @ 2009-11-29 10:08  不眠小C  阅读(619)  评论(0)    收藏  举报