c# - 从现有表中部分加载实体
问题描述
更新:
抱歉,我在降级到EFCore
from后出现错误5.0
,3.1.
我认为这个错误是由于我试图用DBSet<Entity_StuffINeed>
. 实际上,清洁和重建解决了这个问题。上下文的错误。
System.TypeLoadException:来自程序集“Microsoft.EntityFrameworkCore.SqlServer,版本=3.1.13.0,文化=中性,PublicKeyToken=adb9793829ddae60”的“Microsoft.EntityFrameworkCore.SqlServer.Query.Internal.SqlServerSqlTranslatingExpressionVisitorFactory”类型中的“方法“创建”没有一个实施。
原来的:
我正在连接到现有数据库并且无法编辑表。实体非常大。我使用脚手架来获取模型类。
public partial class Entity_Database
{
public Entity_Database()
{
CollectionRef1 = new HashSet<CollectionRef1 >();
... (12 other collectiosn here)
CollectionRef13 = new HashSet<CollectionRef13 >();
}
public int Prop1 { get; set; }
...(47 other props here)
public int? Prop48 { get; set; }
public virtual Ref1 Ref1 { get; set; }
...
public virtual Ref12 Ref12 { get; set; }
public virtual ICollection<CollectionRef1> CollectionRef1 { get; set; }
...
public virtual ICollection<CollectionRef13> CollectionRef13 { get; set; }
}
但我只需要这些属性的一小部分。
public class Entity_StuffINeed
{
public int Prop1 {get;set;}
public string Prop4 {get;set;}
public DateTime Prop8 {get;set;}
}
我可以使用 SQL,然后手动映射到我的对象:
SELECT Prop1, Prop4, Prop8 FROM Entity_Database;
但我找不到在 EFcore 中做类似事情的方法。
- 如果我尝试使用脚手架上下文,启动需要几分钟。
- 如果我尝试使用 Entity_StuffINeed 作为 DBSet,当我尝试访问 DBSet“从 EFCore SqlServer 创建没有实现”时会出现错误。(这是有道理的,因为如果我编辑一个元素,它将不知道如何将这些更改传播回数据库)
我的猜测是我使用了错误的工具。Dapper 不允许我非常喜欢的 Linq 语法。如果在 EFcore 中不可能,我应该使用什么?
解决方案
推荐阅读
- ios - 触发动作时,mockNavigationController 返回当前 viewController,不推送
- r - 按字符匹配和字符串长度分组
- jquery - 为什么拖动事件对jQuery实现没有任何影响?
- suitecrm - 如何修复 crm 输出中的“..{content:”错误
- ios - iOS swift 4中的Facebook登录失败
- java - 将 n 大小的数组拆分为 k-box
- ubuntu-16.04 - VMWare Ubuntu 警告我没有磁盘空间,但 GParted 显示有很多空间
- html - 在不知道实际宽度的情况下将项目居中
- php - 如何在 php echo 中执行 mysql 查询?
- c++ - 返回变量为 void (*)(void)