创建字典时出现 Ling-to SQL 编译器错误
我正在尝试开发一个简单的 WP7 数据库应用程序,它使用 Linq2SQL 来查询数据库,但今天我设法收到一个内部编译器错误:(
我的查询的简化版本如下(Results
是保存我的搜索结果数据的类):
var query =
(
from x in MyTable
join y in MyOtherTable on x.Key equals y.Key
where SqlMethods.Like(x.Field, "%" + searchTerm + "%")
select new Results
{
MyResultField = new Dictionary<MyEnum,string>()
{
{ MyEnum.Value, x.Field },
{ MyEnum.OtherValue, y.Field }
},
...
}
);
但是,尝试创建一个像这样的新字典会导致大量编译器错误,即使我已经进行了搜索,但我。不知道该怎么做此时无需尝试创建字典即可获得类似的结果。
对于绝望的新手有什么想法吗?!提前非常感谢!
更新
抱歉,我忘记包含编译器了。除了#6 之外,它们对我来说都是胡言乱语,但如果它有帮助的话......
# Error 1 Internal Compiler Error: stage 'BEGIN' MyProject
# Error 2 Internal Compiler Error: stage 'EMIT' MyProject
# Error 3 Internal Compiler Error: stage 'COMPILE' MyProject
# Error 4 Internal Compiler Error: stage 'COMPILE' C:\...\ViewModel.cs MyProject
# Error 5 Internal Compiler Error: stage 'COMPILE' symbol '<global namespace>' C:\...\ViewModel.cs MyProject
# Error 6 Internal Compiler Error (0xc0000005 at address 681AB648): likely culprit is 'BIND'.
# An internal error has occurred in the compiler. To work around this problem, try simplifying or changing the program near the locations listed below. Locations at the top of the list are closer to the point at which the internal error occurred. Errors such as this can be reported to Microsoft by using the /errorreport option.
# MyProject
# Error 7 Internal Compiler Error: stage 'COMPILE' symbol 'ChineseClassmate' C:\...\ViewModel.cs 12 11 MyProject
# Error 8 Internal Compiler Error: stage 'COMPILE' symbol 'ChineseClassmate.MyProject' C:\...\ViewModel.cs 12 11 MyProject
# Error 9 Internal Compiler Error: stage 'COMPILE' symbol 'ChineseClassmate.MyProject.ViewModel' C:\...\ViewModel.cs 12 11 MyProject
# Error 10 Internal Compiler Error: stage 'COMPILE' symbol 'MyProject.ViewModel.MyProjectViewModel' C:\...\ViewModel.cs 17 15 MyProject
# Error 11 Internal Compiler Error: stage 'COMPILE' symbol 'MyProject.ViewModel.MyProjectViewModel.SearchDatabase(string)' C:\...\ViewModel.cs 57 15 MyProject
# Error 12 Internal Compiler Error: stage 'COMPILE' symbol 'MyProject.ViewModel.MyProjectViewModel.SearchDatabase(string)' C:\...\ViewModel.cs 57 15 MyProject
# Error 13 Internal Compiler Error: stage 'COMPILE' symbol 'MyProject.ViewModel.MyProjectViewModel.SearchDatabase(string)' C:\...\ViewModel.cs 57 15 MyProject
# Error 14 Internal Compiler Error: stage 'BIND' symbol 'MyProject.ViewModel.MyProjectViewModel.SearchDatabase(string)' C:\...\ViewModel.cs 57 15 MyProject
I'm trying to develop a simple WP7 database app which uses Linq2SQL to query the database, but today I managed to received an internal compiler error :(
A simplified version of my query is below (Results
is a class which holds my search results data):
var query =
(
from x in MyTable
join y in MyOtherTable on x.Key equals y.Key
where SqlMethods.Like(x.Field, "%" + searchTerm + "%")
select new Results
{
MyResultField = new Dictionary<MyEnum,string>()
{
{ MyEnum.Value, x.Field },
{ MyEnum.OtherValue, y.Field }
},
...
}
);
However, trying to create a new Dictionary
like this results in a raft of compiler errors, even though IntelliSense doesn't object. I've searched around, but I'm not sure how to achieve a similar result without trying to create a Dictionary
at this point.
Any ideas for a hopeless newbie?! Many thanks in advance!
Update
Sorry, I forgot to include the compiler errors. Apart from #6, they're gibberish to me, but if it helps ...
# Error 1 Internal Compiler Error: stage 'BEGIN' MyProject
# Error 2 Internal Compiler Error: stage 'EMIT' MyProject
# Error 3 Internal Compiler Error: stage 'COMPILE' MyProject
# Error 4 Internal Compiler Error: stage 'COMPILE' C:\...\ViewModel.cs MyProject
# Error 5 Internal Compiler Error: stage 'COMPILE' symbol '<global namespace>' C:\...\ViewModel.cs MyProject
# Error 6 Internal Compiler Error (0xc0000005 at address 681AB648): likely culprit is 'BIND'.
# An internal error has occurred in the compiler. To work around this problem, try simplifying or changing the program near the locations listed below. Locations at the top of the list are closer to the point at which the internal error occurred. Errors such as this can be reported to Microsoft by using the /errorreport option.
# MyProject
# Error 7 Internal Compiler Error: stage 'COMPILE' symbol 'ChineseClassmate' C:\...\ViewModel.cs 12 11 MyProject
# Error 8 Internal Compiler Error: stage 'COMPILE' symbol 'ChineseClassmate.MyProject' C:\...\ViewModel.cs 12 11 MyProject
# Error 9 Internal Compiler Error: stage 'COMPILE' symbol 'ChineseClassmate.MyProject.ViewModel' C:\...\ViewModel.cs 12 11 MyProject
# Error 10 Internal Compiler Error: stage 'COMPILE' symbol 'MyProject.ViewModel.MyProjectViewModel' C:\...\ViewModel.cs 17 15 MyProject
# Error 11 Internal Compiler Error: stage 'COMPILE' symbol 'MyProject.ViewModel.MyProjectViewModel.SearchDatabase(string)' C:\...\ViewModel.cs 57 15 MyProject
# Error 12 Internal Compiler Error: stage 'COMPILE' symbol 'MyProject.ViewModel.MyProjectViewModel.SearchDatabase(string)' C:\...\ViewModel.cs 57 15 MyProject
# Error 13 Internal Compiler Error: stage 'COMPILE' symbol 'MyProject.ViewModel.MyProjectViewModel.SearchDatabase(string)' C:\...\ViewModel.cs 57 15 MyProject
# Error 14 Internal Compiler Error: stage 'BIND' symbol 'MyProject.ViewModel.MyProjectViewModel.SearchDatabase(string)' C:\...\ViewModel.cs 57 15 MyProject
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我不相信你能做到这一点。它必须能够将此调用转换为有效的 sql 并在其中使用新对象,因此我相信会导致失败,因为它不能转换为在数据库端运行。您必须获取结果然后转换为字典(.ToDictionary())
I don't believe you can do this. It must be able to translate this call into valid sql and using new objects in there as such I believe will cause a failure as that is not convertible to run all on the db side. You must get your results AND THEN convert to a dictionary (.ToDictionary())
为每一行创建一个字典并且每个字典只有相同的两个键有点奇怪。您最好将
Results
修改为只有两个字段,如下所示:如果您迫切需要一个字典,那么可能会返回匿名类型的值,然后在强制执行查询后像
.ToArray()
之类的东西,您可以使用现有的字典代码创建Results
对象。我希望这有帮助。
It's a bit odd to create a dictionary for each row and have each dictionary only have the same two keys. You're better off modifying the
Results
to just have two fields like so:If you desperately have to have a dictionary there then maybe return the values in an anonymous type, then, after forcing the query execution with something like
.ToArray()
, you can create yourResults
objects with the existing dictionary code.I hope this helps.