Entity Framework does not pull through data from s

2019-07-26 20:36发布

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.

here are my two statements.

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();

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.

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.

2条回答
时光不老,我们不散
2楼-- · 2019-07-26 20:57

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 ?

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 ?

查看更多
爱情/是我丢掉的垃圾
3楼-- · 2019-07-26 21:04

Ok, I restarted my computer and now everything seems ok.... Very strange, but at least it is now working.

查看更多
登录 后发表回答