设为首页 加入收藏

TOP

BLToolkitLinq-provider(七)
2015-11-21 01:53:40 来源: 作者: 【 】 浏览:7
Tags:BLToolkitLinq-provider
y] AND ([t1].[BirthDate] IS NULL AND [t2].[BirthDate] IS NULL OR [t1].[BirthDate] IS NOT NULL AND [t2].[BirthDate] IS NOT NULL AND [t1].[BirthDate] = [t2].[BirthDate]) AND ([t1].[HireDate] IS NULL AND [t2].[HireDate] IS NULL OR [t1].[HireDate] IS NOT NULL AND [t2].[HireDate] IS NOT NULL AND [t1].[HireDate] = [t2].[HireDate]) AND [t1].[Address] = [t2].[Address] AND [t1].[City] = [t2].[City] AND [t1].[Region] = [t2].[Region] AND [t1].[PostalCode] = [t2].[PostalCode] AND [t1].[Country] = [t2].[Country] AND [t1].[HomePhone] = [t2].[HomePhone] AND [t1].[Extension] = [t2].[Extension] AND [t1].[Notes] = [t2].[Notes] AND ([t1].[ReportsTo] IS NULL AND [t2].[ReportsTo] IS NULL OR [t1].[ReportsTo] IS NOT NULL AND [t2].[ReportsTo] IS NOT NULL AND [t1].[ReportsTo] = [t2].[ReportsTo]) AND [t1].[PhotoPath] = [t2].[PhotoPath]

Not only is this request without tears to look it is impossible, it is still not working as among the fields of the table Employees have a field of type ntext, which can not be compared.

COUNCIL

Be careful in the description of the data model. BLToolkit uses meta-information about your entities to optimize queries, and its absence can lead to a less than optimal query construction.

Inheritance

Support for inheritance BLToolkit made in the image and likeness of inheritance in Linq To SQL. To organize inheritance require special markup entities as in the following code:

[TableName("Products")]
[InheritanceMapping(Code="True",  Type=typeof(DiscontinuedProduct))]
[InheritanceMapping(Code="False", Type=typeof(ActiveProduct))]
public abstract class Product
{
    [PrimaryKey, Identity]                      public int      ProductID;
    [NotNull]                                    public  string    ProductName;
                                                 public  int ? SupplierID;
                                                 public  int ? CategoryID;
                                                 public  string    QuantityPerUnit;
                                                 public  decimal ? UnitPrice,
                                                 public  short ? UnitsInStock;
                                                 public  short ? UnitsOnOrder;
                                                 public  short ? ReorderLevel;
    [MapField(IsInheritanceDiscriminator=true)] public bool     Discontinued;
}

public class ActiveProduct : Product
{
}

public class DiscontinuedProduct : Product
{
}

Here the field Discontinued acts as a discriminator - a sign, according to which the objects are divided into certain types. Attribute InheritanceMapping allows you to compare the value of this field and the type that corresponds to this field. In this example, the types of ActiveProduct and DiscontinuedProduct are not specific to the type of field, but in principle it is not prohibited.

More information can be found at the following link - Linq To the SQL Inheritance.

Below are a few examples of the use of inheritance.

from p in db.DiscontinuedProduct
select p;

SQL:

SELECT
    [p].[ProductID],
    [P]. [ProductName]
    [p].[SupplierID],
    [p].[CategoryID],
    [p].[QuantityPerUnit],
    [p].[UnitPrice],
    [p].[UnitsInStock],
    [p].[UnitsOnOrder],
    [p].[ReorderLevel],
    [p].[Discontinued]
FROM
    [Products] [p]
WHERE
    [p].[Discontinued] = 'True'

In exactly the same SQL will be generated for the following test:

from c in db.Product
where c is Northwind.DiscontinuedProduct
select c;

Standard features .NET Framework

BLToolkit supports conversion into SQL standard features about four .NET Framework. This includes functions for working with strings, dates, mathematical functions, conversion functions and converting scalar data types. If a feature has no direct counterpart in

首页 上一页 4 5 6 7 8 9 10 下一页 尾页 7/13/13
】【打印繁体】【投稿】【收藏】 【推荐】【举报】【评论】 【关闭】 【返回顶部
分享到: 
上一篇Mysql Master Slave Config 下一篇BI-SSAS简介篇

评论

帐  号: 密码: (新用户注册)
验 证 码:
表  情:
内  容: