实体框架不会从某些列中提取数据 [英] Entity Framework does not pull through data from some columns

查看:64
本文介绍了实体框架不会从某些列中提取数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我遇到一个问题,即我的entityframework模型无法从SQL Server数据库表的两列中提取数据.它会遍历所有其他列,但无论表中的内容如何,​​两个整数列始终为零.

I have an issue where my entityframework model is not pulling though data from two columns of a sql server database table. It pulls through all the others but two integer columns are always zero regardless of what it says in the table.

这是我的两个声明.

statList = (from s in context.Stats where s.Make.ToUpper() == manufacturer.ToUpper() select s).ToList();

int i = (from d in context.Stats where d.StatID == 22 select d.ItemCount).FirstOrDefault();

第一条语句显然会遍历实体对象列表,并且每个对象的ItemCount和OptionCount列都设置为零.

The first statement obviously pulls through a list of entity objects, and this has the ItemCount and OptionCount columns set to zero for every object.

第二条语句仅提取我想要的特定记录的列,并提取正确的值.....

The second statement pulls through just the column I want for a specific record and it pulls out the correct value.....

到底是怎么回事?我从未见过这种情况.

What on earth is going on? I have never seen this happen before.

我尝试删除edmx文件并从头开始重新创建,但是它仍然做同样的事情.我检查了列映射,它们看起来都很好.

I have tried deleting the edmx file and recreating from scratch but it still does the same thing. I have checked the column mappings and they all look fine.

推荐答案

我相信您已将"statList"声明为列表或poco对象.您是否检查了Itemcount列表中绑定的数据类型和默认值是什么?

I believe u declared 'statList' as list or poco object. Did u checked what are the data types and default values binding in the list for Itemcount ?

当列值绑定到列表时,在所需的列出现任何问题之前,它有时会返回零(在这种情况下,如果列A"值在"Itemcount"列之前绑定,并且如果列A未正确绑定)),接下来的所有列将不会显示正确的数据,在这种情况下,由于它是INT数据类型列,因此将显示0.检查其他列的值可能是位转换等;是否正确绑定?

It will return zero some times, when the column value binding to list, before the required column is having any problem (in this case if 'column A' value binds before 'Itemcount' column and if column A does not binds properly), all the next columns will not show correct data and in this case it will show 0 as it is INT datatype column. Check the values of other columns may be Bit conversion etc; whether binds correctly or not ?

这篇关于实体框架不会从某些列中提取数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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