【发布时间】:2011-08-10 20:31:11
【问题描述】:
以下内容如何给我一个错误,类似于“Linq To Entities 中只允许使用无参数构造函数和初始化程序”。我正在尝试从我的实体生成 HTML 以使用 AJAX 更新 HTML 表。
public class Foo
{
public int Bar1 { get; set; }
public string Bar2 { get; set; }
public DateTime Bar3 { get; set; }
}
XElement[] elements = (
from x in FooEntities.Foos
select new XElement("tr",
new XElement("td", HttpUtility.HtmlEncode(x.Bar1)),
new XElement("td", HttpUtility.HtmlEncode(x.Bar2)),
new XElement("td", HttpUtility.HtmlEncode(x.Bar3)))
)
.ToArray<XElement>(); // Error
XElement html = new XElement("table", headerXElement, elements);
【问题讨论】:
-
附带说明,您不需要在
ToArray调用中指定类型参数,因为它将由编译器推断。
标签: ajax linq linq-to-entities linq-to-xml