【发布时间】:2012-12-08 19:16:16
【问题描述】:
我正在与 EF 合作并有一些疑问。这是我的代码
IEnumerable<Customer> customers = from c in context.Customers
select new Customer
{
ID = c.ID,
Name = c.Name,
LastName = c.LastName,
DepID = c.DepID,
Editable = SomeStruct.Check(c.DepID)
}
public struct SomeStruct
{
public static bool Check(int depID)
{
//Here I have some logic
}
}
它工作正常。
但是,如果我将SomeStruct 声明为class,它将失败。
我的问题是:
- 为什么会这样?
- 使用静态函数会强制执行查询吗?
【问题讨论】:
-
我可以确认一下:如果
SomeStruct是class,但方法仍然是static,那么它不起作用 - 我理解正确吗?如果是这样:会发生什么?有什么例外? -
当 SomeStruct 是一个结构体时,你确定你的代码能正常工作吗?您能否将 ToList() 添加到您的 select 语句中,看看是否一切正常?
标签: c# entity-framework linq-to-entities linq-to-objects