Lưu ý
Cần có ủy quyền mới truy nhập được vào trang này. Bạn có thể thử đăng nhập hoặc thay đổi thư mục.
Cần có ủy quyền mới truy nhập được vào trang này. Bạn có thể thử thay đổi thư mục.
A constant expression consists of a constant value. Constant values are directly converted to constant command tree expressions, without any translation on the client. This includes expressions that result in a constant value. Therefore, data source behavior should be expected for all expressions involving constants. This can result in behavior that differs from CLR behavior.
The following example shows a constant expression that is evaluated on the server.
Decimal totalDue = 200 + 3;
using (AdventureWorksEntities context = new AdventureWorksEntities())
{
IQueryable<string> salesInfo =
from s in context.SalesOrderHeaders
where s.TotalDue >= totalDue
select s.SalesOrderNumber;
Console.WriteLine("Sales order numbers:");
foreach (string orderNum in salesInfo)
{
Console.WriteLine(orderNum);
}
}
Dim totalDue = 200 + 3
Using context As New AdventureWorksEntities()
Dim salesInfo = _
From s In context.SalesOrderHeaders _
Where s.TotalDue >= totalDue _
Select s.SalesOrderNumber
Console.WriteLine("Sales order numbers:")
For Each orderNum As String In salesInfo
Console.WriteLine(orderNum)
Next
End Using
LINQ to Entities does not support using a user class as a constant. However, a property reference on a user class is considered a constant, and will be converted to a command tree constant expression and executed on the data source.