转载:C#3.0入门系列(七)--之OR工具介绍

  不得不再次给关注dlinq 的朋友道歉了。好久都没有更新blog 了。因为工作的变动,还要赶期限,没有时间关注这里了。

先发布一则消息。Orcas Beta1, 这个才是beta1,可以到http://www.microsoft.com/downloads/details.aspx?FamilyID=f10fb5df-e369-4db4-b9a7-845dbf793368&DisplayLang=en 下载。5月1号的版本。最早4月19号就出来过一个,只是没有在意。还有一个http://www.microsoft.com/downloads/details.aspx?FamilyID=36b6609e-6f3d-40f4-8c7d-ad111679d8dc&DisplayLang=en 。 一个是self-extracting 版本的,一个是Virtual PC version的。不知道什么区别。没有装过。

本节舍去原来的计划,而改讲映射工具。在入门三一文中,我们提到了sqlmetal这个工具。http://www.cnblogs.com/126/archive/2006/09/06/492332.html sqlmetal的功能是将数据库的信息抽提出来,生成映射代码。Orcas还有另外一个工具,就是O/R Designer.

先讲sqlmetal. 自上次的版本后,sqlmetal,又增加了一些新的功能。比如,支持SQLCE版本的Sql Server, 支持直接输入connection string, 等等。 这是sqlmetal的帮助信息,是不是比上次多了很多?

ContractedBlock.gif ExpandedBlockStart.gif
None.gif
None.gifMicrosoft (R) Database Mapping Generator 2008 Beta 2 version 1.00.20612
None.giffor Microsoft (R) .NET Framework version 3.5
None.gifCopyright (C) Microsoft Corporation. All rights reserved.
None.gif
None.gifSqlMetal [options] [
<input file>]
None.gif
None.gif  Generates code and mapping for the LINQ to SQL component of the .NET framework. SqlMetal can:
None.gif  - Generate source code and mapping attributes or a mapping file from a database.
None.gif  - Generate an intermediate dbml file for customization from the database.
None.gif  - Generate code and mapping attributes or mapping file from a dbml file.
None.gif
None.gifOptions:
None.gif  /server:
<name>             Database server name.
None.gif  /database:
<name>           Database catalog on server.
None.gif  /user:
<name>               Login user ID (default: use Windows Authentication).
None.gif  /password:
<password>       Login password (default: use Windows Authentication).
None.gif  /conn:
<connection string>  Database connection string. Cannot be used with /server, /database, /us
None.gifer or /password options.
None.gif  /timeout:
<seconds>         Timeout value to use when SqlMetal accesses the database (default: 0 wh
None.gifich means infinite).
None.gif
None.gif  /views                     Extract database views.
None.gif  /functions                 Extract database functions.
None.gif  /sprocs                    Extract stored procedures.
None.gif
None.gif  /dbml[:file]               Output as dbml. Cannot be used with /map option.
None.gif  /code[:file]               Output as source code. Cannot be used with /dbml option.
None.gif  /map[:file]                Generate mapping file, not attributes. Cannot be used with /dbml option
None.gif.
None.gif
None.gif  /language:
<language>       Language for source code: VB or C# (default: derived from extension on code file name).
None.gif  /namespace:
<name>          Namespace of generated code (default: no namespace).
None.gif  /context:
<type>            Name of data context class (default: derived from database name).
None.gif  /entitybase:
<type>         Base class of entity classes in the generated code (default: entities have no base class).
None.gif  /pluralize                 Automatically pluralize or singularize class and member names using English language rules.
None.gif  /serialization:
<option>    Generate serializable classes: None or Unidirectional (default: None).
None.gif  /provider:
<type>           Provider type (default: provider is determined at run time).
None.gif
None.gif  
<input file>               May be a SqlExpress mdf file, a SqlCE sdf file, or a dbml intermediate file.
None.gif
None.gifCreate code from SqlServer:
None.gif  SqlMetal /server:myserver /database:northwind /code:nwind.cs /namespace:nwind
None.gif
None.gifGenerate intermediate dbml file from SqlServer:
None.gif  SqlMetal /server:myserver /database:northwind /dbml:northwind.dbml /namespace:nwind
None.gif
None.gifGenerate code with external mapping from dbml:
None.gif  SqlMetal /code:nwind.cs /map:nwind.map northwind.dbml
None.gif
None.gifGenerate dbml from a SqlCE sdf file:
None.gif  SqlMetal /dbml:northwind.dbml northwind.sdf
None.gif
None.gifGenerate dbml from SqlExpress local server:
None.gif  SqlMetal /server:.\sqlexpress /database:northwind /dbml:northwind.dbml
None.gif
None.gifGenerate dbml by using a connection string in the command line:
None.gif  SqlMetal /conn:"server='myserver'; database='northwind'" /dbml:northwind.dbml
 
因为sqlmetal 已经讲过,不再多讲,大家知道它是个命令行的工具,用来做映射数据库信息的,会使用就可以。 再接着讲O/R Designer. 新建任一工程。右击工程,选择add->new item. 如图所示:

弹出item对话框,category中选择data,然后选择Linq to Sql Class 如图所示:

选择添加。这样,你的工程就多了一个O/R Desiger项目。在菜单View->Sever Explore 打开Sever Explore,添加一个Data Connection, 如图所示:

后,填写数据库服务器,用户名,密码和数据库名。如果,你没有,你可以使用Sql Express 版本。添加之后的效果,如图所示:

打开刚才添加的DataClasses1.dbml 文件,将Sever Explore中的Customer 表或view拖入Designer中来,如图所示:



也可以将
Store procedure User define function 拖进来,会在方法面板上形成方法。如图所示:


 

如果,两个表之间有关系,OR Designer可以显示它们的关系,将Order表和 OderDetail表拖入 如图所示:

打开DataClasses1. Designer.cs 文件,你就可以看到OR Designer给你产生的映射代码了。

ContractedBlock.gif ExpandedBlockStart.gif
None.gifusing System.Data.Linq;
None.gif    
using System.Data.Linq.Mapping;
None.gif    
using System.Data;
None.gif    
using System.Collections.Generic;
None.gif    
using System.Reflection;
None.gif    
using System.Linq;
None.gif    
using System.Linq.Expressions;
None.gif    
using System.ComponentModel;
None.gif    
using System;
None.gif    
None.gif    
None.gif    [System.Data.Linq.Mapping.DatabaseAttribute(Name
="northwind_may06ctp")]
None.gif    
public partial class DataClasses1DataContext : System.Data.Linq.DataContext
ExpandedBlockStart.gifContractedBlock.gif    
dot.gif{
InBlock.gif        
InBlock.gif        
private static System.Data.Linq.Mapping.MappingSource mappingSource = new AttributeMappingSource();
InBlock.gif        
ContractedSubBlock.gifExpandedSubBlockStart.gif    
Extensibility Method Definitions#region Extensibility Method Definitions
InBlock.gif    partial 
void OnCreated();
InBlock.gif    partial 
void InsertOrder(Order instance);
InBlock.gif    partial 
void UpdateOrder(Order instance);
InBlock.gif    partial 
void DeleteOrder(Order instance);
InBlock.gif    partial 
void InsertOrder_Detail(Order_Detail instance);
InBlock.gif    partial 
void UpdateOrder_Detail(Order_Detail instance);
InBlock.gif    partial 
void DeleteOrder_Detail(Order_Detail instance);
ExpandedSubBlockEnd.gif    
#endregion

InBlock.gif        
InBlock.gif        
static DataClasses1DataContext()
ExpandedSubBlockStart.gifContractedSubBlock.gif        
dot.gif{
ExpandedSubBlockEnd.gif        }

InBlock.gif        
InBlock.gif        
public DataClasses1DataContext(string connection) : 
InBlock.gif                
base(connection, mappingSource)
ExpandedSubBlockStart.gifContractedSubBlock.gif        
dot.gif{
InBlock.gif            OnCreated();
ExpandedSubBlockEnd.gif        }

InBlock.gif        
InBlock.gif        
public DataClasses1DataContext(System.Data.IDbConnection connection) : 
InBlock.gif                
base(connection, mappingSource)
ExpandedSubBlockStart.gifContractedSubBlock.gif        
dot.gif{
InBlock.gif            OnCreated();
ExpandedSubBlockEnd.gif        }

InBlock.gif        
InBlock.gif        
public DataClasses1DataContext(string connection, System.Data.Linq.Mapping.MappingSource mappingSource) : 
InBlock.gif                
base(connection, mappingSource)
ExpandedSubBlockStart.gifContractedSubBlock.gif        
dot.gif{
InBlock.gif            OnCreated();
ExpandedSubBlockEnd.gif        }

InBlock.gif        
InBlock.gif        
public DataClasses1DataContext(System.Data.IDbConnection connection, System.Data.Linq.Mapping.MappingSource mappingSource) : 
InBlock.gif                
base(connection, mappingSource)
ExpandedSubBlockStart.gifContractedSubBlock.gif        
dot.gif{
InBlock.gif            OnCreated();
ExpandedSubBlockEnd.gif        }

InBlock.gif        
InBlock.gif        
public DataClasses1DataContext() : 
InBlock.gif                
base(global::SqlMetalUtil.Properties.Settings.Default.northwind_may06ctpConnectionString, mappingSource)
ExpandedSubBlockStart.gifContractedSubBlock.gif        
dot.gif{
InBlock.gif            OnCreated();
ExpandedSubBlockEnd.gif        }

InBlock.gif        
InBlock.gif        
public System.Data.Linq.Table<Order> Orders
ExpandedSubBlockStart.gifContractedSubBlock.gif        
dot.gif{
InBlock.gif            
get
ExpandedSubBlockStart.gifContractedSubBlock.gif            
dot.gif{
InBlock.gif                
return this.GetTable<Order>();
ExpandedSubBlockEnd.gif            }

ExpandedSubBlockEnd.gif        }

InBlock.gif        
InBlock.gif        
public System.Data.Linq.Table<Order_Detail> Order_Details
ExpandedSubBlockStart.gifContractedSubBlock.gif        
dot.gif{
InBlock.gif            
get
ExpandedSubBlockStart.gifContractedSubBlock.gif            
dot.gif{
InBlock.gif                
return this.GetTable<Order_Detail>();
ExpandedSubBlockEnd.gif            }

ExpandedSubBlockEnd.gif        }

InBlock.gif        
InBlock.gif        [Function(Name
="dbo.CategoriesInsert")]
InBlock.gif        
public int CategoriesInsert([Parameter(Name="@CategoryID", DbType="int")] System.Nullable<int> CategoryID, [Parameter(Name="@CategoryName", DbType="nvarchar")] string CategoryName, [Parameter(Name="@Description", DbType="ntext")] string Description, [Parameter(Name="@Picture", DbType="image")] byte[] Picture)
ExpandedSubBlockStart.gifContractedSubBlock.gif        
dot.gif{
InBlock.gif            IExecuteResult result 
= this.ExecuteMethodCall(this, ((MethodInfo)(MethodInfo.GetCurrentMethod())), CategoryID, CategoryName, Description, Picture);
InBlock.gif            
return ((int)(result.ReturnValue));
ExpandedSubBlockEnd.gif        }

ExpandedBlockEnd.gif    }

None.gif    
None.gif    [Table(Name
="dbo.Orders")]
None.gif    
public partial class Order : INotifyPropertyChanging, INotifyPropertyChanged
ExpandedBlockStart.gifContractedBlock.gif    
dot.gif{
InBlock.gif        
InBlock.gif        
private static PropertyChangingEventArgs emptyChangingEventArgs = new PropertyChangingEventArgs(String.Empty);
InBlock.gif        
InBlock.gif        
private int _OrderID;
InBlock.gif        
InBlock.gif        
private string _CustomerID;
InBlock.gif        
InBlock.gif        
private System.Nullable<int> _EmployeeID;
InBlock.gif        
InBlock.gif        
private System.Nullable<System.DateTime> _OrderDate;
InBlock.gif        
InBlock.gif        
private System.Nullable<System.DateTime> _RequiredDate;
InBlock.gif        
InBlock.gif        
private System.Nullable<System.DateTime> _ShippedDate;
InBlock.gif        
InBlock.gif        
private System.Nullable<int> _ShipVia;
InBlock.gif        
InBlock.gif        
private System.Nullable<decimal> _Freight;
InBlock.gif        
InBlock.gif        
private string _ShipName;
InBlock.gif        
InBlock.gif        
private string _ShipAddress;
InBlock.gif        
InBlock.gif        
private string _ShipCity;
InBlock.gif        
InBlock.gif        
private string _ShipRegion;
InBlock.gif        
InBlock.gif        
private string _ShipPostalCode;
InBlock.gif        
InBlock.gif        
private string _ShipCountry;
InBlock.gif        
InBlock.gif        
private EntitySet<Order_Detail> _Order_Details;
InBlock.gif        
ContractedSubBlock.gifExpandedSubBlockStart.gif    
Extensibility Method Definitions#region Extensibility Method Definitions
InBlock.gif    partial 
void OnLoaded();
InBlock.gif    partial 
void OnValidate();
InBlock.gif    partial 
void OnCreated();
InBlock.gif    partial 
void OnOrderIDChanging(int value);
InBlock.gif    partial 
void OnOrderIDChanged();
InBlock.gif    partial 
void OnCustomerIDChanging(string value);
InBlock.gif    partial 
void OnCustomerIDChanged();
InBlock.gif    partial 
void OnEmployeeIDChanging(System.Nullable<int> value);
InBlock.gif    partial 
void OnEmployeeIDChanged();
InBlock.gif    partial 
void OnOrderDateChanging(System.Nullable<System.DateTime> value);
InBlock.gif    partial 
void OnOrderDateChanged();
InBlock.gif    partial 
void OnRequiredDateChanging(System.Nullable<System.DateTime> value);
InBlock.gif    partial 
void OnRequiredDateChanged();
InBlock.gif    partial 
void OnShippedDateChanging(System.Nullable<System.DateTime> value);
InBlock.gif    partial 
void OnShippedDateChanged();
InBlock.gif    partial 
void OnShipViaChanging(System.Nullable<int> value);
InBlock.gif    partial 
void OnShipViaChanged();
InBlock.gif    partial 
void OnFreightChanging(System.Nullable<decimal> value);
InBlock.gif    partial 
void OnFreightChanged();
InBlock.gif    partial 
void OnShipNameChanging(string value);
InBlock.gif    partial 
void OnShipNameChanged();
InBlock.gif    partial 
void OnShipAddressChanging(string value);
InBlock.gif    partial 
void OnShipAddressChanged();
InBlock.gif    partial 
void OnShipCityChanging(string value);
InBlock.gif    partial 
void OnShipCityChanged();
InBlock.gif    partial 
void OnShipRegionChanging(string value);
InBlock.gif    partial 
void OnShipRegionChanged();
InBlock.gif    partial 
void OnShipPostalCodeChanging(string value);
InBlock.gif    partial 
void OnShipPostalCodeChanged();
InBlock.gif    partial 
void OnShipCountryChanging(string value);
InBlock.gif    partial 
void OnShipCountryChanged();
ExpandedSubBlockEnd.gif    
#endregion

InBlock.gif        
InBlock.gif        
public Order()
ExpandedSubBlockStart.gifContractedSubBlock.gif        
dot.gif{
InBlock.gif            OnCreated();
InBlock.gif            
this._Order_Details = new EntitySet<Order_Detail>(new Action<Order_Detail>(this.attach_Order_Details), new Action<Order_Detail>(this.detach_Order_Details));
ExpandedSubBlockEnd.gif        }

InBlock.gif        
InBlock.gif        [Column(Storage
="_OrderID", AutoSync=AutoSync.OnInsert, DbType="Int NOT NULL IDENTITY", IsPrimaryKey=true, IsDbGenerated=true)]
InBlock.gif        
public int OrderID
ExpandedSubBlockStart.gifContractedSubBlock.gif        
dot.gif{
InBlock.gif            
get
ExpandedSubBlockStart.gifContractedSubBlock.gif            
dot.gif{
InBlock.gif                
return this._OrderID;
ExpandedSubBlockEnd.gif            }

InBlock.gif            
set
ExpandedSubBlockStart.gifContractedSubBlock.gif            
dot.gif{
InBlock.gif                
if ((this._OrderID != value))
ExpandedSubBlockStart.gifContractedSubBlock.gif                
dot.gif{
InBlock.gif                    
this.OnOrderIDChanging(value);
InBlock.gif                    
this.SendPropertyChanging();
InBlock.gif                    
this._OrderID = value;
InBlock.gif                    
this.SendPropertyChanged("OrderID");
InBlock.gif                    
this.OnOrderIDChanged();
ExpandedSubBlockEnd.gif                }

ExpandedSubBlockEnd.gif            }

ExpandedSubBlockEnd.gif        }

InBlock.gif        
InBlock.gif        [Column(Storage
="_CustomerID", DbType="NChar(5)")]
InBlock.gif        
public string CustomerID
ExpandedSubBlockStart.gifContractedSubBlock.gif        
dot.gif{
InBlock.gif            
get
ExpandedSubBlockStart.gifContractedSubBlock.gif            
dot.gif{
InBlock.gif                
return this._CustomerID;
ExpandedSubBlockEnd.gif            }

InBlock.gif            
set
ExpandedSubBlockStart.gifContractedSubBlock.gif            
dot.gif{
InBlock.gif                
if ((this._CustomerID != value))
ExpandedSubBlockStart.gifContractedSubBlock.gif                
dot.gif{
InBlock.gif                    
this.OnCustomerIDChanging(value);
InBlock.gif                    
this.SendPropertyChanging();
InBlock.gif                    
this._CustomerID = value;
InBlock.gif                    
this.SendPropertyChanged("CustomerID");
InBlock.gif                    
this.OnCustomerIDChanged();
ExpandedSubBlockEnd.gif                }

ExpandedSubBlockEnd.gif            }

ExpandedSubBlockEnd.gif        }

InBlock.gif        
InBlock.gif        [Column(Storage
="_EmployeeID", DbType="Int")]
InBlock.gif        
public System.Nullable<int> EmployeeID
ExpandedSubBlockStart.gifContractedSubBlock.gif        
dot.gif{
InBlock.gif            
get
ExpandedSubBlockStart.gifContractedSubBlock.gif            
dot.gif{
InBlock.gif                
return this._EmployeeID;
ExpandedSubBlockEnd.gif            }

InBlock.gif            
set
ExpandedSubBlockStart.gifContractedSubBlock.gif            
dot.gif{
InBlock.gif                
if ((this._EmployeeID != value))
ExpandedSubBlockStart.gifContractedSubBlock.gif                
dot.gif{
InBlock.gif                    
this.OnEmployeeIDChanging(value);
InBlock.gif                    
this.SendPropertyChanging();
InBlock.gif                    
this._EmployeeID = value;
InBlock.gif                    
this.SendPropertyChanged("EmployeeID");
InBlock.gif                    
this.OnEmployeeIDChanged();
ExpandedSubBlockEnd.gif                }

ExpandedSubBlockEnd.gif            }

ExpandedSubBlockEnd.gif        }

InBlock.gif        
InBlock.gif        [Column(Storage
="_OrderDate", DbType="DateTime")]
InBlock.gif        
public System.Nullable<System.DateTime> OrderDate
ExpandedSubBlockStart.gifContractedSubBlock.gif        
dot.gif{
InBlock.gif            
get
ExpandedSubBlockStart.gifContractedSubBlock.gif            
dot.gif{
InBlock.gif                
return this._OrderDate;
ExpandedSubBlockEnd.gif            }

InBlock.gif            
set
ExpandedSubBlockStart.gifContractedSubBlock.gif            
dot.gif{
InBlock.gif                
if ((this._OrderDate != value))
ExpandedSubBlockStart.gifContractedSubBlock.gif                
dot.gif{
InBlock.gif                    
this.OnOrderDateChanging(value);
InBlock.gif                    
this.SendPropertyChanging();
InBlock.gif                    
this._OrderDate = value;
InBlock.gif                    
this.SendPropertyChanged("OrderDate");
InBlock.gif                    
this.OnOrderDateChanged();
ExpandedSubBlockEnd.gif                }

ExpandedSubBlockEnd.gif            }

ExpandedSubBlockEnd.gif        }

InBlock.gif        
InBlock.gif        [Column(Storage
="_RequiredDate", DbType="DateTime")]
InBlock.gif        
public System.Nullable<System.DateTime> RequiredDate
ExpandedSubBlockStart.gifContractedSubBlock.gif        
dot.gif{
InBlock.gif            
get
ExpandedSubBlockStart.gifContractedSubBlock.gif            
dot.gif{
InBlock.gif                
return this._RequiredDate;
ExpandedSubBlockEnd.gif            }

InBlock.gif            
set
ExpandedSubBlockStart.gifContractedSubBlock.gif            
dot.gif{
InBlock.gif                
if ((this._RequiredDate != value))
ExpandedSubBlockStart.gifContractedSubBlock.gif                
dot.gif{
InBlock.gif                    
this.OnRequiredDateChanging(value);
InBlock.gif                    
this.SendPropertyChanging();
InBlock.gif                    
this._RequiredDate = value;
InBlock.gif                    
this.SendPropertyChanged("RequiredDate");
InBlock.gif                    
this.OnRequiredDateChanged();
ExpandedSubBlockEnd.gif                }

ExpandedSubBlockEnd.gif            }

ExpandedSubBlockEnd.gif        }

InBlock.gif        
InBlock.gif        [Column(Storage
="_ShippedDate", DbType="DateTime")]
InBlock.gif        
public System.Nullable<System.DateTime> ShippedDate
ExpandedSubBlockStart.gifContractedSubBlock.gif        
dot.gif{
InBlock.gif            
get
ExpandedSubBlockStart.gifContractedSubBlock.gif            
dot.gif{
InBlock.gif                
return this._ShippedDate;
ExpandedSubBlockEnd.gif            }

InBlock.gif            
set
ExpandedSubBlockStart.gifContractedSubBlock.gif            
dot.gif{
InBlock.gif                
if ((this._ShippedDate != value))
ExpandedSubBlockStart.gifContractedSubBlock.gif                
dot.gif{
InBlock.gif                    
this.OnShippedDateChanging(value);
InBlock.gif                    
this.SendPropertyChanging();
InBlock.gif                    
this._ShippedDate = value;
InBlock.gif                    
this.SendPropertyChanged("ShippedDate");
InBlock.gif                    
this.OnShippedDateChanged();
ExpandedSubBlockEnd.gif                }

ExpandedSubBlockEnd.gif            }

ExpandedSubBlockEnd.gif        }

InBlock.gif        
InBlock.gif        [Column(Storage
="_ShipVia", DbType="Int")]
InBlock.gif        
public System.Nullable<int> ShipVia
ExpandedSubBlockStart.gifContractedSubBlock.gif        
dot.gif{
InBlock.gif            
get
ExpandedSubBlockStart.gifContractedSubBlock.gif            
dot.gif{
InBlock.gif                
return this._ShipVia;
ExpandedSubBlockEnd.gif            }

InBlock.gif            
set
ExpandedSubBlockStart.gifContractedSubBlock.gif            
dot.gif{
InBlock.gif                
if ((this._ShipVia != value))
ExpandedSubBlockStart.gifContractedSubBlock.gif                
dot.gif{
InBlock.gif                    
this.OnShipViaChanging(value);
InBlock.gif                    
this.SendPropertyChanging();
InBlock.gif                    
this._ShipVia = value;
InBlock.gif                    
this.SendPropertyChanged("ShipVia");
InBlock.gif                    
this.OnShipViaChanged();
ExpandedSubBlockEnd.gif                }

ExpandedSubBlockEnd.gif            }

ExpandedSubBlockEnd.gif        }

InBlock.gif        
InBlock.gif        [Column(Storage
="_Freight", DbType="Money")]
InBlock.gif        
public System.Nullable<decimal> Freight
ExpandedSubBlockStart.gifContractedSubBlock.gif        
dot.gif{
InBlock.gif            
get
ExpandedSubBlockStart.gifContractedSubBlock.gif            
dot.gif{
InBlock.gif                
return this._Freight;
ExpandedSubBlockEnd.gif            }

InBlock.gif            
set
ExpandedSubBlockStart.gifContractedSubBlock.gif            
dot.gif{
InBlock.gif                
if ((this._Freight != value))
ExpandedSubBlockStart.gifContractedSubBlock.gif                
dot.gif{
InBlock.gif                    
this.OnFreightChanging(value);
InBlock.gif                    
this.SendPropertyChanging();
InBlock.gif                    
this._Freight = value;
InBlock.gif                    
this.SendPropertyChanged("Freight");
InBlock.gif                    
this.OnFreightChanged();
ExpandedSubBlockEnd.gif                }

ExpandedSubBlockEnd.gif            }

ExpandedSubBlockEnd.gif        }

InBlock.gif        
InBlock.gif        [Column(Storage
="_ShipName", DbType="NVarChar(40)")]
InBlock.gif        
public string ShipName
ExpandedSubBlockStart.gifContractedSubBlock.gif        
dot.gif{
InBlock.gif            
get
ExpandedSubBlockStart.gifContractedSubBlock.gif            
dot.gif{
InBlock.gif                
return this._ShipName;
ExpandedSubBlockEnd.gif            }

InBlock.gif            
set
ExpandedSubBlockStart.gifContractedSubBlock.gif            
dot.gif{
InBlock.gif                
if ((this._ShipName != value))
ExpandedSubBlockStart.gifContractedSubBlock.gif                
dot.gif{
InBlock.gif                    
this.OnShipNameChanging(value);
InBlock.gif                    
this.SendPropertyChanging();
InBlock.gif                    
this._ShipName = value;
InBlock.gif                    
this.SendPropertyChanged("ShipName");
InBlock.gif                    
this.OnShipNameChanged();
ExpandedSubBlockEnd.gif                }

ExpandedSubBlockEnd.gif            }

ExpandedSubBlockEnd.gif        }

InBlock.gif        
InBlock.gif        [Column(Storage
="_ShipAddress", DbType="NVarChar(60)")]
InBlock.gif        
public string ShipAddress
ExpandedSubBlockStart.gifContractedSubBlock.gif        
dot.gif{
InBlock.gif            
get
ExpandedSubBlockStart.gifContractedSubBlock.gif            
dot.gif{
InBlock.gif                
return this._ShipAddress;
ExpandedSubBlockEnd.gif            }

InBlock.gif            
set
ExpandedSubBlockStart.gifContractedSubBlock.gif            
dot.gif{
InBlock.gif                
if ((this._ShipAddress != value))
ExpandedSubBlockStart.gifContractedSubBlock.gif                
dot.gif{
InBlock.gif                    
this.OnShipAddressChanging(value);
InBlock.gif                    
this.SendPropertyChanging();
InBlock.gif                    
this._ShipAddress = value;
InBlock.gif                    
this.SendPropertyChanged("ShipAddress");
InBlock.gif                    
this.OnShipAddressChanged();
ExpandedSubBlockEnd.gif                }

ExpandedSubBlockEnd.gif            }

ExpandedSubBlockEnd.gif        }

InBlock.gif        
InBlock.gif        [Column(Storage
="_ShipCity", DbType="NVarChar(15)")]
InBlock.gif        
public string ShipCity
ExpandedSubBlockStart.gifContractedSubBlock.gif        
dot.gif{
InBlock.gif            
get
ExpandedSubBlockStart.gifContractedSubBlock.gif            
dot.gif{
InBlock.gif                
return this._ShipCity;
ExpandedSubBlockEnd.gif            }

InBlock.gif            
set
ExpandedSubBlockStart.gifContractedSubBlock.gif            
dot.gif{
InBlock.gif                
if ((this._ShipCity != value))
ExpandedSubBlockStart.gifContractedSubBlock.gif                
dot.gif{
InBlock.gif                    
this.OnShipCityChanging(value);
InBlock.gif                    
this.SendPropertyChanging();
InBlock.gif                    
this._ShipCity = value;
InBlock.gif                    
this.SendPropertyChanged("ShipCity");
InBlock.gif                    
this.OnShipCityChanged();
ExpandedSubBlockEnd.gif                }

ExpandedSubBlockEnd.gif            }

ExpandedSubBlockEnd.gif        }

InBlock.gif        
InBlock.gif        [Column(Storage
="_ShipRegion", DbType="NVarChar(15)")]
InBlock.gif        
public string ShipRegion
ExpandedSubBlockStart.gifContractedSubBlock.gif        
dot.gif{
InBlock.gif            
get
ExpandedSubBlockStart.gifContractedSubBlock.gif            
dot.gif{
InBlock.gif                
return this._ShipRegion;
ExpandedSubBlockEnd.gif            }

InBlock.gif            
set
ExpandedSubBlockStart.gifContractedSubBlock.gif            
dot.gif{
InBlock.gif                
if ((this._ShipRegion != value))
ExpandedSubBlockStart.gifContractedSubBlock.gif                
dot.gif{
InBlock.gif                    
this.OnShipRegionChanging(value);
InBlock.gif                    
this.SendPropertyChanging();
InBlock.gif                    
this._ShipRegion = value;
InBlock.gif                    
this.SendPropertyChanged("ShipRegion");
InBlock.gif                    
this.OnShipRegionChanged();
ExpandedSubBlockEnd.gif                }

ExpandedSubBlockEnd.gif            }

ExpandedSubBlockEnd.gif        }

InBlock.gif        
InBlock.gif        [Column(Storage
="_ShipPostalCode", DbType="NVarChar(10)")]
InBlock.gif        
public string ShipPostalCode
ExpandedSubBlockStart.gifContractedSubBlock.gif        
dot.gif{
InBlock.gif            
get
ExpandedSubBlockStart.gifContractedSubBlock.gif            
dot.gif{
InBlock.gif                
return this._ShipPostalCode;
ExpandedSubBlockEnd.gif            }

InBlock.gif            
set
ExpandedSubBlockStart.gifContractedSubBlock.gif            
dot.gif{
InBlock.gif                
if ((this._ShipPostalCode != value))
ExpandedSubBlockStart.gifContractedSubBlock.gif                
dot.gif{
InBlock.gif                    
this.OnShipPostalCodeChanging(value);
InBlock.gif                    
this.SendPropertyChanging();
InBlock.gif                    
this._ShipPostalCode = value;
InBlock.gif                    
this.SendPropertyChanged("ShipPostalCode");
InBlock.gif                    
this.OnShipPostalCodeChanged();
ExpandedSubBlockEnd.gif                }

ExpandedSubBlockEnd.gif            }

ExpandedSubBlockEnd.gif        }

InBlock.gif        
InBlock.gif        [Column(Storage
="_ShipCountry", DbType="NVarChar(15)")]
InBlock.gif        
public string ShipCountry
ExpandedSubBlockStart.gifContractedSubBlock.gif        
dot.gif{
InBlock.gif            
get
ExpandedSubBlockStart.gifContractedSubBlock.gif            
dot.gif{
InBlock.gif                
return this._ShipCountry;
ExpandedSubBlockEnd.gif            }

InBlock.gif            
set
ExpandedSubBlockStart.gifContractedSubBlock.gif            
dot.gif{
InBlock.gif                
if ((this._ShipCountry != value))
ExpandedSubBlockStart.gifContractedSubBlock.gif                
dot.gif{
InBlock.gif                    
this.OnShipCountryChanging(value);
InBlock.gif                    
this.SendPropertyChanging();
InBlock.gif                    
this._ShipCountry = value;
InBlock.gif                    
this.SendPropertyChanged("ShipCountry");
InBlock.gif                    
this.OnShipCountryChanged();
ExpandedSubBlockEnd.gif                }

ExpandedSubBlockEnd.gif            }

ExpandedSubBlockEnd.gif        }

InBlock.gif        
InBlock.gif        [Association(Name
="Order_Order_Detail", Storage="_Order_Details", OtherKey="OrderID")]
InBlock.gif        
public EntitySet<Order_Detail> Order_Details
ExpandedSubBlockStart.gifContractedSubBlock.gif        
dot.gif{
InBlock.gif            
get
ExpandedSubBlockStart.gifContractedSubBlock.gif            
dot.gif{
InBlock.gif                
return this._Order_Details;
ExpandedSubBlockEnd.gif            }

InBlock.gif            
set
ExpandedSubBlockStart.gifContractedSubBlock.gif            
dot.gif{
InBlock.gif                
this._Order_Details.Assign(value);
ExpandedSubBlockEnd.gif            }

ExpandedSubBlockEnd.gif        }

InBlock.gif        
InBlock.gif        
public event PropertyChangingEventHandler PropertyChanging;
InBlock.gif        
InBlock.gif        
public event PropertyChangedEventHandler PropertyChanged;
InBlock.gif        
InBlock.gif        
protected virtual void SendPropertyChanging()
ExpandedSubBlockStart.gifContractedSubBlock.gif        
dot.gif{
InBlock.gif            
if ((this.PropertyChanging != null))
ExpandedSubBlockStart.gifContractedSubBlock.gif            
dot.gif{
InBlock.gif                
this.PropertyChanging(this, emptyChangingEventArgs);
ExpandedSubBlockEnd.gif            }

ExpandedSubBlockEnd.gif        }

InBlock.gif        
InBlock.gif        
protected virtual void SendPropertyChanged(String propertyName)
ExpandedSubBlockStart.gifContractedSubBlock.gif        
dot.gif{
InBlock.gif            
if ((this.PropertyChanged != null))
ExpandedSubBlockStart.gifContractedSubBlock.gif            
dot.gif{
InBlock.gif                
this.PropertyChanged(thisnew PropertyChangedEventArgs(propertyName));
ExpandedSubBlockEnd.gif            }

ExpandedSubBlockEnd.gif        }

InBlock.gif        
InBlock.gif        
private void attach_Order_Details(Order_Detail entity)
ExpandedSubBlockStart.gifContractedSubBlock.gif        
dot.gif{
InBlock.gif            
this.SendPropertyChanging();
InBlock.gif            entity.Order 
= this;
InBlock.gif            
this.SendPropertyChanged("Order_Details");
ExpandedSubBlockEnd.gif        }

InBlock.gif        
InBlock.gif        
private void detach_Order_Details(Order_Detail entity)
ExpandedSubBlockStart.gifContractedSubBlock.gif        
dot.gif{
InBlock.gif            
this.SendPropertyChanging();
InBlock.gif            entity.Order 
= null;
InBlock.gif            
this.SendPropertyChanged("Order_Details");
ExpandedSubBlockEnd.gif        }

ExpandedBlockEnd.gif    }

None.gif    
None.gif    [Table(Name
="dbo.[Order Details]")]
None.gif    
public partial class Order_Detail : INotifyPropertyChanging, INotifyPropertyChanged
ExpandedBlockStart.gifContractedBlock.gif    
dot.gif{
InBlock.gif        
InBlock.gif        
private static PropertyChangingEventArgs emptyChangingEventArgs = new PropertyChangingEventArgs(String.Empty);
InBlock.gif        
InBlock.gif        
private int _OrderID;
InBlock.gif        
InBlock.gif        
private int _ProductID;
InBlock.gif        
InBlock.gif        
private decimal _UnitPrice;
InBlock.gif        
InBlock.gif        
private short _Quantity;
InBlock.gif        
InBlock.gif        
private float _Discount;
InBlock.gif        
InBlock.gif        
private EntityRef<Order> _Order;
InBlock.gif        
ContractedSubBlock.gifExpandedSubBlockStart.gif    
Extensibility Method Definitions#region Extensibility Method Definitions
InBlock.gif    partial 
void OnLoaded();
InBlock.gif    partial 
void OnValidate();
InBlock.gif    partial 
void OnCreated();
InBlock.gif    partial 
void OnOrderIDChanging(int value);
InBlock.gif    partial 
void OnOrderIDChanged();
InBlock.gif    partial 
void OnProductIDChanging(int value);
InBlock.gif    partial 
void OnProductIDChanged();
InBlock.gif    partial 
void OnUnitPriceChanging(decimal value);
InBlock.gif    partial 
void OnUnitPriceChanged();
InBlock.gif    partial 
void OnQuantityChanging(short value);
InBlock.gif    partial 
void OnQuantityChanged();
InBlock.gif    partial 
void OnDiscountChanging(float value);
InBlock.gif    partial 
void OnDiscountChanged();
ExpandedSubBlockEnd.gif    
#endregion

InBlock.gif        
InBlock.gif        
public Order_Detail()
ExpandedSubBlockStart.gifContractedSubBlock.gif        
dot.gif{
InBlock.gif            OnCreated();
InBlock.gif            
this._Order = default(EntityRef<Order>);
ExpandedSubBlockEnd.gif        }

InBlock.gif        
InBlock.gif        [Column(Storage
="_OrderID", DbType="Int NOT NULL", IsPrimaryKey=true)]
InBlock.gif        
public int OrderID
ExpandedSubBlockStart.gifContractedSubBlock.gif        
dot.gif{
InBlock.gif            
get
ExpandedSubBlockStart.gifContractedSubBlock.gif            
dot.gif{
InBlock.gif                
return this._OrderID;
ExpandedSubBlockEnd.gif            }

InBlock.gif            
set
ExpandedSubBlockStart.gifContractedSubBlock.gif            
dot.gif{
InBlock.gif                
if ((this._OrderID != value))
ExpandedSubBlockStart.gifContractedSubBlock.gif                
dot.gif{
InBlock.gif                    
if (this._Order.HasLoadedOrAssignedValue)
ExpandedSubBlockStart.gifContractedSubBlock.gif                    
dot.gif{
InBlock.gif                        
throw new System.Data.Linq.ForeignKeyReferenceAlreadyHasValueException();
ExpandedSubBlockEnd.gif                    }

InBlock.gif                    
this.OnOrderIDChanging(value);
InBlock.gif                    
this.SendPropertyChanging();
InBlock.gif                    
this._OrderID = value;
InBlock.gif                    
this.SendPropertyChanged("OrderID");
InBlock.gif                    
this.OnOrderIDChanged();
ExpandedSubBlockEnd.gif                }

ExpandedSubBlockEnd.gif            }

ExpandedSubBlockEnd.gif        }

InBlock.gif        
InBlock.gif        [Column(Storage
="_ProductID", DbType="Int NOT NULL", IsPrimaryKey=true)]
InBlock.gif        
public int ProductID
ExpandedSubBlockStart.gifContractedSubBlock.gif        
dot.gif{
InBlock.gif            
get
ExpandedSubBlockStart.gifContractedSubBlock.gif            
dot.gif{
InBlock.gif                
return this._ProductID;
ExpandedSubBlockEnd.gif            }

InBlock.gif            
set
ExpandedSubBlockStart.gifContractedSubBlock.gif            
dot.gif{
InBlock.gif                
if ((this._ProductID != value))
ExpandedSubBlockStart.gifContractedSubBlock.gif                
dot.gif{
InBlock.gif                    
this.OnProductIDChanging(value);
InBlock.gif                    
this.SendPropertyChanging();
InBlock.gif                    
this._ProductID = value;
InBlock.gif                    
this.SendPropertyChanged("ProductID");
InBlock.gif                    
this.OnProductIDChanged();
ExpandedSubBlockEnd.gif                }

ExpandedSubBlockEnd.gif            }

ExpandedSubBlockEnd.gif        }

InBlock.gif        
InBlock.gif        [Column(Storage
="_UnitPrice", DbType="Money NOT NULL")]
InBlock.gif        
public decimal UnitPrice
ExpandedSubBlockStart.gifContractedSubBlock.gif        
dot.gif{
InBlock.gif            
get
ExpandedSubBlockStart.gifContractedSubBlock.gif            
dot.gif{
InBlock.gif                
return this._UnitPrice;
ExpandedSubBlockEnd.gif            }

InBlock.gif            
set
ExpandedSubBlockStart.gifContractedSubBlock.gif            
dot.gif{
InBlock.gif                
if ((this._UnitPrice != value))
ExpandedSubBlockStart.gifContractedSubBlock.gif                
dot.gif{
InBlock.gif                    
this.OnUnitPriceChanging(value);
InBlock.gif                    
this.SendPropertyChanging();
InBlock.gif                    
this._UnitPrice = value;
InBlock.gif                    
this.SendPropertyChanged("UnitPrice");
InBlock.gif                    
this.OnUnitPriceChanged();
ExpandedSubBlockEnd.gif                }

ExpandedSubBlockEnd.gif            }

ExpandedSubBlockEnd.gif        }

InBlock.gif        
InBlock.gif        [Column(Storage
="_Quantity", DbType="SmallInt NOT NULL")]
InBlock.gif        
public short Quantity
ExpandedSubBlockStart.gifContractedSubBlock.gif        
dot.gif{
InBlock.gif            
get
ExpandedSubBlockStart.gifContractedSubBlock.gif            
dot.gif{
InBlock.gif                
return this._Quantity;
ExpandedSubBlockEnd.gif            }

InBlock.gif            
set
ExpandedSubBlockStart.gifContractedSubBlock.gif            
dot.gif{
InBlock.gif                
if ((this._Quantity != value))
ExpandedSubBlockStart.gifContractedSubBlock.gif                
dot.gif{
InBlock.gif                    
this.OnQuantityChanging(value);
InBlock.gif                    
this.SendPropertyChanging();
InBlock.gif                    
this._Quantity = value;
InBlock.gif                    
this.SendPropertyChanged("Quantity");
InBlock.gif                    
this.OnQuantityChanged();
ExpandedSubBlockEnd.gif                }

ExpandedSubBlockEnd.gif            }

ExpandedSubBlockEnd.gif        }

InBlock.gif        
InBlock.gif        [Column(Storage
="_Discount", DbType="Real NOT NULL")]
InBlock.gif        
public float Discount
ExpandedSubBlockStart.gifContractedSubBlock.gif        
dot.gif{
InBlock.gif            
get
ExpandedSubBlockStart.gifContractedSubBlock.gif            
dot.gif{
InBlock.gif                
return this._Discount;
ExpandedSubBlockEnd.gif            }

InBlock.gif            
set
ExpandedSubBlockStart.gifContractedSubBlock.gif            
dot.gif{
InBlock.gif                
if ((this._Discount != value))
ExpandedSubBlockStart.gifContractedSubBlock.gif                
dot.gif{
InBlock.gif                    
this.OnDiscountChanging(value);
InBlock.gif                    
this.SendPropertyChanging();
InBlock.gif                    
this._Discount = value;
InBlock.gif                    
this.SendPropertyChanged("Discount");
InBlock.gif                    
this.OnDiscountChanged();
ExpandedSubBlockEnd.gif                }

ExpandedSubBlockEnd.gif            }

ExpandedSubBlockEnd.gif        }

InBlock.gif        
InBlock.gif        [Association(Name
="Order_Order_Detail", Storage="_Order", ThisKey="OrderID", IsForeignKey=true)]
InBlock.gif        
public Order Order
ExpandedSubBlockStart.gifContractedSubBlock.gif        
dot.gif{
InBlock.gif            
get
ExpandedSubBlockStart.gifContractedSubBlock.gif            
dot.gif{
InBlock.gif                
return this._Order.Entity;
ExpandedSubBlockEnd.gif            }

InBlock.gif            
set
ExpandedSubBlockStart.gifContractedSubBlock.gif            
dot.gif{
InBlock.gif                Order previousValue 
= this._Order.Entity;
InBlock.gif                
if (((previousValue != value) 
InBlock.gif                            
|| (this._Order.HasLoadedOrAssignedValue == false)))
ExpandedSubBlockStart.gifContractedSubBlock.gif                
dot.gif{
InBlock.gif                    
this.SendPropertyChanging();
InBlock.gif                    
if ((previousValue != null))
ExpandedSubBlockStart.gifContractedSubBlock.gif                    
dot.gif{
InBlock.gif                        
this._Order.Entity = null;
InBlock.gif                        previousValue.Order_Details.Remove(
this);
ExpandedSubBlockEnd.gif                    }

InBlock.gif                    
this._Order.Entity = value;
InBlock.gif                    
if ((value != null))
ExpandedSubBlockStart.gifContractedSubBlock.gif                    
dot.gif{
InBlock.gif                        value.Order_Details.Add(
this);
InBlock.gif                        
this._OrderID = value.OrderID;
ExpandedSubBlockEnd.gif                    }

InBlock.gif                    
else
ExpandedSubBlockStart.gifContractedSubBlock.gif                    
dot.gif{
InBlock.gif                        
this._OrderID = default(int);
ExpandedSubBlockEnd.gif                    }

InBlock.gif                    
this.SendPropertyChanged("Order");
ExpandedSubBlockEnd.gif                }

ExpandedSubBlockEnd.gif            }

ExpandedSubBlockEnd.gif        }

InBlock.gif        
InBlock.gif        
public event PropertyChangingEventHandler PropertyChanging;
InBlock.gif        
InBlock.gif        
public event PropertyChangedEventHandler PropertyChanged;
InBlock.gif        
InBlock.gif        
protected virtual void SendPropertyChanging()
ExpandedSubBlockStart.gifContractedSubBlock.gif        
dot.gif{
InBlock.gif            
if ((this.PropertyChanging != null))
ExpandedSubBlockStart.gifContractedSubBlock.gif            
dot.gif{
InBlock.gif                
this.PropertyChanging(this, emptyChangingEventArgs);
ExpandedSubBlockEnd.gif            }

ExpandedSubBlockEnd.gif        }

InBlock.gif        
InBlock.gif        
protected virtual void SendPropertyChanged(String propertyName)
ExpandedSubBlockStart.gifContractedSubBlock.gif        
dot.gif{
InBlock.gif            
if ((this.PropertyChanged != null))
ExpandedSubBlockStart.gifContractedSubBlock.gif            
dot.gif{
InBlock.gif                
this.PropertyChanged(thisnew PropertyChangedEventArgs(propertyName));
ExpandedSubBlockEnd.gif            }

ExpandedSubBlockEnd.gif        }

ExpandedBlockEnd.gif    }


本节介绍了O/R Designer的基本用法,下节讲一些比较高级的用法。O/R Designer相对与sqlmetal的好处就可以设计类的继承关系(下节再讲),而sqlmetal 相对于O/R Designer是可以一次性抽提所有表的信息,快速便捷。而且sqlmetal支持一些O/R Designer无法支持的信息提取。

转载于:https://www.cnblogs.com/jacklaw/archive/2007/07/03/804682.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值