首页 新闻 会员 周边 捐助

Linq创建XML文件失败.不知如何解决.

0
悬赏园豆:20 [已关闭问题] 关闭于 2011-09-21 13:19
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.

实在是找不到解决的方法,特此来请教,谢谢。

denli的主页 denli | 初学一级 | 园豆:19
提问于:2011-03-15 10:19
< >
分享
所有回答(1)
0
2012 | 园豆:21645 (高人七级) | 2011-03-16 08:25
清除回答草稿
   您需要登录以后才能回答,未注册用户请先注册