从实体中排除不可存在的列 [英] Exclude nonnullable column from Entity

查看:67
本文介绍了从实体中排除不可存在的列的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个包含很多列的数据库表。我使用EF来访问表中的数据,但我的应用程序并不真正需要来自所有列的数据。表中有很多行,所有行都很慢,我正在寻找一种方法来加快速度。

我曾经想过,如果我可以从我的实体中排除某些列,那么事情可能会更快地运行。无论如何,我可以从我的实体中排除一些列吗?我尝试了它,并得到一个错误,必须映射不可存在的列(我想要删除的大多数列是不可空的)。还有什么我可以尝试的吗?这甚至有助于加快速度吗?

I have a database table that has a lot of columns. I am using EF to access the data in the table, but my application doesn't really need the data from all of the columns. There are a lot of rows in the table and it is slow to fetch them all and I am looking for a way to speed things up.

I had the thought that if I could exlude some of the columns from my entity that things may run more quickly. Is there anyway that I can exclude some of the columns from my entity? I tried it and got an error that the nonnullable columns had to be mapped (most of the columns I want to drop are nonnullable). Is there anything else I can try? Would this even help speed things up?

推荐答案

看起来我刚刚发布完全相同的问题:-)

我明白需要在更新的情况下设置默认值 - 没有办法舍入 - 但只是因为您设置默认值并不意味着正在检索列。只有将它映射到属性时才会检索它。

也许有一种方法可以将实体设置为只读,这样就不需要设置默认值了......
Looks like I just posted the exact same question :-)

I understand the need to set the default value in case of updates - there is no way round that - but just because you set a default value doesn't mean the column is being retrieved. It will only be retrieved if you map it to a property.

Maybe there is a way to set the entity as read-only so that setting the default values is not necessary...


这篇关于从实体中排除不可存在的列的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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