您的位置:首页 > 数据库

LINQ to SQL的对象模型和基于Attribute的映射

2008-05-06 22:35 417 查看
[索引页]

挖.在上几周我写拉关于LINQ 的标准操作符号的文章,接着有发一篇关于转化泛型参数类型的文章,转化泛型参数类型能帮助我们使用LINQ to DataSet中扩展返回集合的泛型参数类型.如果你还关注LINQ to JavaScript.现在几来看LINQ to SQL,

[Database(Name="AdventureWorks")]

public class AWDB

[Table(Name = "HumanResources.Employee")]

public class Employee

[Table(Name = "Person.Contact")]

public class Contact

[Column(DBType = "int", IsPrimaryKey=true, CanBeNull=false)]

public int EmployeeID;

[Column(DBType = "nvarchar(256)", CanBeNull=false)]

public string LoginID;

[Column(DBType = "nvarchar(15)", CanBeNull=false)]

public string NationalIDNUmber;

[Column(DBType = "int",CanBeNull=false)]

public int ManagerID;

2Expression的使用

[Column(Storage="_UnitPrice", DbType="Money",Expression="UnitPrice + 1.00")]

public System.Nullable<decimal> UnitPrice

[Column(Storage = "_EmployeeID", DbType = "Int")]

public System.Nullable<int> EmployeeID

[Table(Name = "Person.Contact")]

public class Contact

[Table(Name = "Customers")]

public partial class customer

[Table(Name = "Orders")]

public partial class order

[Table(Name = "dbo.[Order Details]")]

public partial class Order_Detail

[StoredProcedure(Name="OrdersBySalesPersonID")]

public IEnumerable OrdersBySalesPersonID([Parameter(DBType = "int")] String param1)

[StoredProcedure(Name = "dbo.uspGetRoleDescription")]

public IEnumerable uspGetRoleDescription([Parameter(Name = "@description")] string description)

[StoredProcedure(Name = "dbo.uspUpdateRole")]

public int uspUpdateRole
([Parameter(Name = "@id")] Nullable id, [Parameter(Name = "@description")] string description)

[StoredProcedure(Name="OrdersBySalesPersonID")]

[return: Parameter(DbType = "numeric")]

public IEnumerable MaxOrderBySalesPersonID([Parameter(DbType = "int")]

String param1)

IExecuteResults results = this.ExecuteMethodCall<OrdersBySalesPersonID>

(this, ((MethodInfo)(MethodInfo.GetCurrentMethod())),

param1);

}

(6)Mapping Functions

LINQ to SQL支持用户定义函数.使用方法就是attribute

[Function(Name="ufnGetcontactInformation")]

Public IQueryable<ufnGetcontactInformation>

ufnGetcontactInformation(System.Nullable<int> ContactID)

{

//

}

PropertyDescritption

DefaultValue(if any)
IComposable

得到或设置是否一个方法被映射到一个函数或一个存储过程.
Name函数名
TypeId

当实现一个派生类时,为这一个Attrbute的得到一个唯一标记.
(7)inheritanceMappingAttribute

使用这个Attribute绘制整个继承层次关系.

欢迎评论

works guo

www.cnblogs.com/worksguo
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: