如何按照「Linq To Entities中只允許無參數的構造函數和初始化程序」的方式給出錯誤信息。我正在嘗試從我的實體生成HTML以使用AJAX更新HTML表格。使用linq-to-entities生成xml的錯誤
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'調用中指定類型參數,因爲它將由編譯器推斷出來。 –