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)
這個構造函數可以自定義connection和mappingSource
?
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();
????????????? }
???????? }
???? }
綁定每列的屬性,set和get方法
?
#pragma warning restore 1591
恢復1591的警告信息
轉載于:https://www.cnblogs.com/sleeplessC/articles/1612911.html
《新程序員》:云原生和全面數字化實踐50位技術專家共同創作,文字、視頻、音頻交互閱讀總結
以上是生活随笔為你收集整理的linq.designer.cs学习笔记的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 先装VS2008再装SQL2005的问题
- 下一篇: 2010:关于 Web 的 30 个预测