Map two different entities to the same table?

后端 未结 2 456
执笔经年
执笔经年 2020-12-02 15:55

I have a table in my database with a lot of fields. Most of the time I need all those fields. There is one scenario, however, where I only need a few of the field

2条回答
  •  有刺的猬
    2020-12-02 16:15

    I would create a View on the database containing only the data you need and add the View to your entity data model.

    If you don't want to modify the database, you can create a Linq to entities or ESQL statement projecting to a POCO class with only the information you need.

    public IQueryable GetView(DBContext context)
    {
        return  (from obj in context.ComplexObjects
                select new SimpleObject() { Property1 = obj.Property1,
                                            Property1 = obj.Property2
                                          }); 
    }
    

提交回复
热议问题