1 private void CrtXml()
2 {
3 using(var edm = new Entities())
4 {
5 var q = from c in edm.TestTable
6 select new
7 {
8 TblName=c.TableName,
9 Cols = from o in edm.TblDetails.Where(p =>p.TableName == c.TableName)
10 select new
11 {
12 ColumnName = c.ColumnName,
13 Descr = c.Descr,
14 ColID = c.ColID,
15 Length = c.Length,
16 ErrMsg= c.ErrMsg
17 }
18
19 };
20
21 var query = new XElement("Tables",
22 from t in q
23 select
24 new XElement("Table",
25 new XElement("TableName", t.TblName),
26 from c in t.Cols
27 select new XElement("Columns",
28 new XAttribute("ColID", c.ColID),
29 new XElement("ColumnName", c.ColumnName),
30 new XElement("Descr", c.Descr),
31 new XElement("Length", c.Length),
32 new XElement("ErrMsg", c.ErrMsg)
33 )));
34 query.Save(@"d:\33.xml");
35
36
37
38 }
39 }
编译没有问题,点执行此方法时,系统报错:
错误内容为:
未处理NotSupportedException
Only parameterless constructors and initializers are supported in LINQ to Entities.
实在是找不到解决的方法,特此来请教,谢谢。