The column name is not valid. [ Node name (if any) = t0,Column name = version ]

给你一囗甜甜゛ 提交于 2019-12-10 03:03:59

问题


I am facing issue while trying to query SQLCE database in my Windows Phone Mango application.

I get exception when I execute

foreach (var item in myDataContext.MyTable.Select(item => item))

The column name is not valid. [ Node name (if any) = t0,Column name = version ]

Strangely, when I execute query based on any individual column, it works fine

foreach (var item in myDataContext.MyTable.Select(item => item.SomeColumn))

Any idea what could be wrong here?


回答1:


I installed LINQ to SQL Debug Visualizer to find out what query exactly is being generated behind the scene and it was

{SELECT [t0].[version], [t0].[ID], [t0].[Volume], ... similarly rest of the columns FROM [MyTable] AS [t0]

This was strange because I didn't had version column in my table (ever). I looked into my model and I found this column defined

[Column(IsVersion = true)]
private Binary version;

I removed column by commenting out these two lines and re-ran the app. Newly generated SQL didn't had any version column and my query worked fine.

I am using SQLCEMangoCodeGenerator for generating LINQ to SQL classes. I guess error is in this tool because of which it generated an extra column which I didn't have in my table




回答2:


I was having the same issue with the "SQLCEMangoCodeGenerator" tool.

I started to use the "SQL Server Compact Toolbox" tool and I haven't had any issues: http://visualstudiogallery.msdn.microsoft.com/0e313dfd-be80-4afb-b5e9-6e74d369f7a1/

(search for "NEW: DataContext" on the above website for a screen shot. Once you've installed the Extension, click the "SQL Server Compact Toolbox" in the Tools menu)




回答3:


I solved this issue by removing the whole database and recreate it.

Obivously, this happens, if you have older version of table in database than you want to use, thus that column does not exist in that table.




回答4:


In SqlCE.sdf with SQL Server Managment Studio run:

DELETE FROM [User] WHERE [User].[UserName] = "zz"

got similar issue with column name not valid, but changed quotations to apostrophes:

DELETE FROM [User] WHERE [User].[UserName] = 'zz'

and it worked!



来源:https://stackoverflow.com/questions/9055617/the-column-name-is-not-valid-node-name-if-any-t0-column-name-version

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!