如何填补实体只是需要的属性(FluentNHibernate)实体、属性、FluentNHibernate

2023-09-05 03:51:17 作者:美人泪在君心

我使用FluentNHibernate访问到我的数据库。我想实现下一个 - 我的实体的只是所需的性能应填写。举例,在一个案件中的所有属性应填写,在第二个案例库应该返回实体标识和名称唯一属性。 这会让SENCE?

I am using FluentNHibernate to access to my database. I would like to implement next - just required properties of my entity should be filled. By example, in one case all properties should be filled, in second case repository should return entity with ID and Name properties only. Does it make sence?

我看到一点的时候,我可以实现一些映射实体 - 根据情况每一个映射。 然后我得到了一些ISessionFactory'ies - 库的使用需要ISessionFactory覆盖所需的案例。嗯..但我不知道它是正确的解决方案。

I see point when I can implement a few mappings for entity - every mapping according to case. Then I get a few ISessionFactory'ies - repository uses required ISessionFactory to cover required case. Hmm.. but I am not sure that it is correct solution.

推荐答案

刚刚创建专门的DTO的ViewModels的每个场景,并选择直接放进去

just create specialised DTOs Viewmodels for each scenario and select directly into them

using NHibernate.Linq;

var user = session.Query<User>()
    .Where(user => user.Name == someName)
    .Select(user => new LoginUser(user.Id, user.Name))
    .FirstOrDefault();