LINQ从SQL Server CE选择:指定的转换无效 [英] LINQ select from SQL Server CE: Specified Cast is not valid

查看:587
本文介绍了LINQ从SQL Server CE选择:指定的转换无效的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

好了第一关,喜每个人,这是我的第一篇文章。

Ok first off, Hi every one this is my first post.

目前业务,我已经创建了一个SQLCE数据库,创建数据上下文和所有的映射,并已成功地填补了数据库数据的负载。到目前为止好,现在如果我要检索的数据,我得到的一个问题。

Right now to business, I have created an SQLCE database, created the data context and all the mappings and have successfully filled the database with a load of data. So far so good, now if I want to retrieve the data I get a problem.

$ C $下获取数据。

Code for getting data

var codes = (from c in App.BonusDatabase.tbRawData
             select c).ToList();

运行,我得到指定的转换是无效的。我猜有一个价值的地方它不喜欢的,我怎么能找到的价值是什么?

Running that I get Specified cast is not valid. I'm guessing there is a value somewhere it doesn't like, how can I find what the value is?

at System.Data.SqlServerCe.SqlCeDataReader.GetFloat(Int32 ordinal)
at Read_RAW(ObjectMaterializer`1 )
at System.Data.Linq.SqlClient.ObjectReaderCompiler.ObjectReader`2.MoveNext()
at System.Collections.Generic.List`1..ctor(IEnumerable`1 collection)
at System.Linq.Enumerable.ToList[TSource](IEnumerable`1 source)
at BAT.Bonus.BonusRun(Int32 Week) in Bonus.cs:line 36
at BAT.Bonus.BonusRun() in Bonus.cs:line 25
at BAT.winMain.worker_DoWork(Object sender, DoWorkEventArgs e) in winMain.xaml.cs:line 91
at System.ComponentModel.BackgroundWorker.OnDoWork(DoWorkEventArgs e)
at System.ComponentModel.BackgroundWorker.WorkerThreadStart(Object argument)

编辑:好一个骗子我复制的SQL创建表查询到另一个程序,并把它算多少次,我有整型,浮点,等计数预期。然后,我重复这与LINQ的映射,它有一个匹配的算的,所以我不认为映射是错误的。

Ok as a cheat I copied the SQL create table query into a another program and got it to count how many times I had int, float, etc. The count is as expected. I then repeated this with the LINQ mapping and it has a matching count, so I don't think the mapping is wrong.

编辑2: 我只是修改了上面的code只选择1场,而不是像这样一切

Edit 2: I just modified the above code to just select 1 field rather than everything like so

var codes = (from c in App.BonusDatabase.tbRawData
        select c.CODE).ToList();

这工作正常,但如果我再切换到另一个领域

This works fine but if I then change to another field

var codes = (from c in App.BonusDatabase.tbRawData
        select c.PPH).ToList();

我得到的错误。因此,这是一个多数民众赞成打起来?如果是的话可能是什么问题,因为其作为浮动在SQL数据库中声明,我的映射

I get the error. So is this the one thats playing up? If so what could be the problem as its declared as float in both SQL database and my mappings

推荐答案

如何tbRawData声明?也许领域定义一个确实实地在数据库不匹配。

How is tbRawData declared? Maybe one of the field definitions doesn't match the field in the database.

这篇关于LINQ从SQL Server CE选择:指定的转换无效的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆