Entity Framework 没有特定列的列表

Entity Framework to List without specific Column

我实际上正在使用 EF 并且对它很陌生。我有一个来自数据库的 EDMX 模型。我必须得到一个实体列表,但在这个 Table 中是二进制列。我想要 Table 中没有二进制数据的对象列表。

我的实体对象看起来像:

public partial class bons
{
    public int id { get; set; }
    public System.DateTime zeitstempel { get; set; }
    public byte[] bonBinaer { get; set; }
    public Nullable<int> tisch_nr { get; set; }
    public bool abgearbeitet { get; set; }
    public int kunde_id { get; set; }
    public string hash { get; set; }
    public string dateiname { get; set; }
    public string tisch_name { get; set; }
    public int gang { get; set; }
    public decimal brutto { get; set; }
    public Nullable<System.DateTime> zeitstempelAbgearbeitet { get; set; }
    public Nullable<int> positionenAnzahl { get; set; }
    public bool manuell { get; set; }
}

我得到的列表如下:

internal static List<bons> holeBongListeNichtAbgearbeitetRestaurant(int kunde_id)
{
    List<bons> rückgabe = new List<bons>();
    using (bonsEntities context = new bonsEntities())
    {
        rückgabe = context.bons.Where(x => x.kunde_id == kunde_id && x.abgearbeitet == false).OrderBy(x => x.zeitstempel).ToList();
    }
    return rückgabe;
}

有人可以帮助如何获得没有 'byte[] bonBinaer' 的列表吗?

您好,您可以将 autoMapper 与 EF 扩展一起使用

赞:https://docs.automapper.org/en/stable/Queryable-Extensions.html

或者,如果您愿意,可以使用 Select() 方法自行完成,例如:

    using (bonsEntities context = new bonsEntities())
            {
               rückgabe = context.bons.Where(x => x.kunde_id == kunde_id && x.abgearbeitet == false).OrderBy(x => x.zeitstempel).Select(xx=> new {
     id = xx.id
     //and all you props
     }).ToList().Select(yy=> new bons{
     id=yy.id
 //and back with other props
     }).ToList();


        }