关于linq to sql多表,笔者将在此文中作出详细的阐述,希望能给大家带来帮助。

创新互联建站坚持“要么做到,要么别承诺”的工作理念,服务领域包括:网站设计制作、网站设计、企业官网、英文网站、手机端网站、网站推广等服务,满足客户于互联网时代的上思网站设计、移动媒体设计的需求,帮助企业找到有效的互联网解决方案。努力成为您成熟可靠的网络建设合作伙伴!
在讲述linq to sql多表之前,先看看生成的两个实体类的构造函数:
1。linq to sql多表之Categories类
- public Categories()
- {
- this._Products = new EntitySet
- (new Action
(this.attach_Products), - new Action
(this.detach_Products)); - OnCreated();
- }
2。linq to sql多表之Products类
- public Products()
- {
- this._Order_Details = new EntitySet
- (new Action
(this.attach_Order_Details), - new Action
(this.detach_Order_Details)); - this._Categories = default(EntityRef
); - this._Suppliers = default(EntityRef
); - OnCreated();
- }
比较生成的构造函数,分别用了EntitySet 类、EntityRef 类分别实现了E一对多关系(One-to-Many)、一对一的关系(one-to-one)
而你在查询一个产品实体而有要得到产品所属分类直接得到linq to sql多表。
- p=new products();
- p.categories.categories.categoriesnameategoryNamentityRef
以上就是对linq to sql多表的详细阐述。