nhibernate实体多重映射
我有实体流畅地映射到现有的 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您不能对一个实体使用两种不同的映射。
您可以做的是使用自定义 SQL用于加载。
You can't use two different mappings for an entity.
What you can do is use custom SQL for loading.