EF6 代码优先 - 在 load() 期间跳过二进制(或任何其他)列
EF6 Code first - skip binary (or any other) columns during load()
我有 ReportingActivity 实体 class。
public class ReportingActivity
{
public int ReportingActivityID { get; set; }
public DateTime ReportingActivitySend { get; set; }
public string Remark { get; set; }
public string SendersCSV { get; set; }
public string MailSenderStatus { get; set; }
public long RptGenerationCostMiliseconds { get; set; }
public DateTime RptGeneratedDateTime { get; set; }
public string RptGeneratedByWinUser { get; set; }
public string RptGeneratedOnMachine { get; set; }
public Int64 Run { get; set; }
public byte[] AttachmentFile { get; set; }
public virtual Report Report { get; set; }
public virtual Employee Employee { get; set; }
public virtual ReportingTask ReportingTask { get; set; }
}
我使用这段代码加载数据:
ctxDetail = new ReportingContext();
ctxDetail.ReportingActivity
.Where(x => x.Employee.EmployeeID == currentEmployee.EmployeeID)
.Load();
我的代码获取所有列(如 SELECT * FROM...)
我的问题是如何跳过 byte[] 列,最好向我推荐一种方法来改进我的代码行以便能够指定确切的列表列数.
您可以使用 Table 拆分和可选的延迟加载来只加载常用的列。
见
https://docs.microsoft.com/en-us/ef/core/modeling/table-splitting
这适用于 EF Core,但它在 EF6 代码优先上的工作方式相同。
通常情况下,在处理记录包含大量、很少访问的详细信息的模式时,将这些详细信息拆分成一个单独的 table 是有益的,正如 David 提到的 /w 一对一关系回到主要记录。这些可以在需要时根据需要预先加载或延迟加载。
如果更改架构不切实际,那么从 table 检索数据时的另一种选择是通过 Select
使用投影来填充仅包含您需要的字段的视图模型,不包括较大的字段领域。这将有助于加快诸如读取视图之类的操作,但是对于诸如执行更新之类的操作,您仍然需要加载整个实体,包括大字段,以确保您不会意外 overwrite/erase 数据。可以在不加载此数据的情况下执行更新,但如果以后管理不善,它会增加一些复杂性和引入错误的风险。
我有 ReportingActivity 实体 class。
public class ReportingActivity
{
public int ReportingActivityID { get; set; }
public DateTime ReportingActivitySend { get; set; }
public string Remark { get; set; }
public string SendersCSV { get; set; }
public string MailSenderStatus { get; set; }
public long RptGenerationCostMiliseconds { get; set; }
public DateTime RptGeneratedDateTime { get; set; }
public string RptGeneratedByWinUser { get; set; }
public string RptGeneratedOnMachine { get; set; }
public Int64 Run { get; set; }
public byte[] AttachmentFile { get; set; }
public virtual Report Report { get; set; }
public virtual Employee Employee { get; set; }
public virtual ReportingTask ReportingTask { get; set; }
}
我使用这段代码加载数据:
ctxDetail = new ReportingContext();
ctxDetail.ReportingActivity
.Where(x => x.Employee.EmployeeID == currentEmployee.EmployeeID)
.Load();
我的代码获取所有列(如 SELECT * FROM...)
我的问题是如何跳过 byte[] 列,最好向我推荐一种方法来改进我的代码行以便能够指定确切的列表列数.
您可以使用 Table 拆分和可选的延迟加载来只加载常用的列。
见
https://docs.microsoft.com/en-us/ef/core/modeling/table-splitting
这适用于 EF Core,但它在 EF6 代码优先上的工作方式相同。
通常情况下,在处理记录包含大量、很少访问的详细信息的模式时,将这些详细信息拆分成一个单独的 table 是有益的,正如 David 提到的 /w 一对一关系回到主要记录。这些可以在需要时根据需要预先加载或延迟加载。
如果更改架构不切实际,那么从 table 检索数据时的另一种选择是通过 Select
使用投影来填充仅包含您需要的字段的视图模型,不包括较大的字段领域。这将有助于加快诸如读取视图之类的操作,但是对于诸如执行更新之类的操作,您仍然需要加载整个实体,包括大字段,以确保您不会意外 overwrite/erase 数据。可以在不加载此数据的情况下执行更新,但如果以后管理不善,它会增加一些复杂性和引入错误的风险。