为TINYINT列生成查询引入了强制转换为int [英] Generated query for tinyint column introduces a CAST to int

查看:806
本文介绍了为TINYINT列生成查询引入了强制转换为int的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我查询一个TINYINT列和实体框架生成引入强制转换为int此列SELECT查询,即使我是用在WHERE子句中的类型字节。

I am querying a tinyint column and entity-framework generates a SELECT query that introduces a CAST to INT for this column even when the value that I am using in the WHERE clause is of the type byte.

看示范,我TINYINT列生成的类型是字节

Looking the Model, the generated Type for my tinyint column is byte.

看代码:

byte byteValue = 6;
var entityList = from r in rep.DataContext.FooTable
                 where r.TinyintColumn == byteValue
                 select r;



展望生成的查询:

Looking the generated query:

SELECT [Extent1].[TinyintColumn] AS [TinyintColumn] WHERE @p__linq__0 = CAST( [Extent1].[TinyintColumn] AS int) 

我在性能严格的限制,所以我不希望任何选择那些CAST。

I have strict restrictions in the performance so I don't want those CAST in any select.

所以,我的问题是对子级,有什么办法避免这种CAST在列TINYINT?还是我做错了什么?

So my question whould be, is there any way to avoid this CAST over the column tinyint? or am I doing something wrong?

先谢谢了。

推荐答案

如果您使用的IList< T>。载列表<字节方式> 实体框架不会投

If you use IList<T>.Contains with a List<byte> the Entity Framework won't cast.

List<byte> byteValue = new List<byte> { 6 };
var entityList = from r in rep.DataContext.FooTable
             where byteValue.Contains(r.TinyintColumn)
             select r;



我遇到了同样的问题,的博客上讲述它

这篇关于为TINYINT列生成查询引入了强制转换为int的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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