【发布时间】:2011-11-25 17:40:54
【问题描述】:
我有这个仓库:
public class RepositorySQLite : IRepository
{
public void Add<T>(T entity)
{
using (ISession session = SessionProviderSqLite.OpenSession())
using (ITransaction transaction = session.BeginTransaction())
{
session.Save(entity);
transaction.Commit();
}
}
...
}
我是这样使用它的:
public class Entity1: IEntity
{
public virtual long SomeProperty { get; set; }
}
public class Entity2: IEntity
{
public virtual long AnotherProperty { get; set; }
}
IEntity entity = new Entity1();
entity.SomeProperty = 123;
IRepository repository = new RepositorySQLite();
repository.Add(entity);
实体映射:
每个实体都有自己的表,名为 Entity1, Entity2, ... 一切正常,但有时 Entity1 存储在 Entity2 表中。 我的代码在不止一个线程上运行。我正在使用 Lock 语句。 Nhibernate 是由 XML 配置的。我正在对所有存储库方法使用 NUnit 测试。 这是我正常工作一年后第一次出现在我的应用中。
可能的解决方案: - 我应该使用 session.Save(string entityName, object entity) 吗?但是怎么做?如何获取 entityName?
【问题讨论】:
-
您的映射是如何定义的?
IEntity是如何定义的? -
@DanielA.White 请查看我的更新。
标签: c# nhibernate sqlite