EntityFramework Core 2.0 跳过加载列 [英] EntityFramework Core 2.0 skip loading column

查看:25
本文介绍了EntityFramework Core 2.0 跳过加载列的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用 EF 核心将一些文件保存到 MSSQL 数据库中,其结构类似于

I'm having some files saved into a MSSQL database using EF core with a structure like

public class UploadedFile
{
    public int Id { get; set; }
    public string Source { get; set; }
    public byte[] Content { get; set; }

我希望能够从数据库加载UploadedFiles"列表,而无需实际从数据库中读取内容列.所以我真的不能用

I want to be able to load the list of "UploadedFiles" from database without actually reading the Content column from the database. So I can't really use

await _context.UploadedFiles.ToListAsync();

我相信我可以在存储过程中使用类似波纹管的东西.

I believe I can use something like bellow with a stored procedure.

_context.Set().FromSql("dbo.spGetUploadedFiles")

但是,有没有其他不涉及使用存储过程的方法?我无法取消映射模型中的列,因为我需要它来插入/读取单个项目.谢谢.

But, is there any other way that would not involve using a stored procedure? I can't un-map the column in the model as I need it for insert/read individual items. Thank you.

推荐答案

使用投影:

var results = _context.UploadedFiles.Select(uf => new { uf.Id, uf.Source });

这篇关于EntityFramework Core 2.0 跳过加载列的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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