nhibernate实体多重映射

发布于 2024-10-19 21:10:56 字数 1051 浏览 0 评论 0原文

我有实体流畅地映射到现有的 oracle 视图:

public class MyEntityMap : ClassMap<MyEntity>
{
    public class MyEntityMap()
    {
        ReadOnly();
        SchemaAction.None();
        //mappings
    }
}

我正在查询 oracle 视图中的实体,并根据某些条件过滤它们,比如说,created_date 超过 14 天。这些实体应写入数据库以供将来报告使用。为此,我创建了一个表,该表在字段方面是 Oracle 视图的精确克隆。我想将完全相同的 MyEntity 映射到我自己的表。像这样的事情:

public class MyHistoricalEntityMap : ClassMap<MyEntity>
{
    public class MyHistoricalEntityMap()
    {
        Table("HistoricalEntities");
        //mappings
    }
}

另外,我有一个负责查询视图的服务,但我想添加一个方法来存储我的历史实体,如下所示:

public class MyEntityService : IMyEntityService
{
    private IRepository<MyEntity> _repository;
    ...    
    public IEnumerable<MyEntity> GetEntities(){...}    
    public void StoreHistoricalEntities(IEnumerable<MyEntity> historicalEntities) {...}
}

所以,问题是:我如何指定,我想要(或nhibernate应该)使用 MyEntityMap 进行查询,但使用 MyHistoricalEntityMap 存储结果?或者我可以应用什么其他解决方案?

谢谢,

I have entity fluently mapped to existing oracle view:

public class MyEntityMap : ClassMap<MyEntity>
{
    public class MyEntityMap()
    {
        ReadOnly();
        SchemaAction.None();
        //mappings
    }
}

I'm querying oracle view for entities and filtering them based on certain criteria, let's say, where created_date more than 14 days. Those entities should be written into the database for future reporting use. For that purpose I've created a table which is exact clone of oracle view in terms of fields. And I'd like to map exactly the same MyEntity to my own table. Something like that:

public class MyHistoricalEntityMap : ClassMap<MyEntity>
{
    public class MyHistoricalEntityMap()
    {
        Table("HistoricalEntities");
        //mappings
    }
}

Also, I have a service responsible for querying view, but I want to add a method to store my historical entities, smth like below:

public class MyEntityService : IMyEntityService
{
    private IRepository<MyEntity> _repository;
    ...    
    public IEnumerable<MyEntity> GetEntities(){...}    
    public void StoreHistoricalEntities(IEnumerable<MyEntity> historicalEntities) {...}
}

So, question is: how do I specify, that I want to (or nhibernate should) use MyEntityMap for querying, but MyHistoricalEntityMap for storing results? Or what other solution can I apply?

Thanks,

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

橙幽之幻 2024-10-26 21:10:56

您不能对一个实体使用两种不同的映射。

可以做的是使用自定义 SQL用于加载

You can't use two different mappings for an entity.

What you can do is use custom SQL for loading.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文