【发布时间】:2019-04-05 12:19:28
【问题描述】:
我有两个类Todo 和TodoLog,我为它们创建了映射,并为它们各自的构造函数创建了一些单元测试。
当我运行这些测试时,我收到错误Could not load type TodoLog. Possible cause no assembly name specified 和内部异常MappingException: persistent class TodoLog not found。
即使我为Todo 构造函数运行测试,错误总是指TodoLog。
这两个类的映射相当简单。
Todo 的映射:
[Class(NameType = typeof()Todo, Table = "Todo")]
public class Todo
{
[Id(-2, Name = "Id")]
[Generator(-1, Class = "native")]
public virtual long Id { get; set; }
[Property]
public virtual string Title { get; set; }
[Property]
public virtual Guid TodoGuid { get; set; }
private IList<TodoLog> logs = new List<TodoLog>();
[Bag(0, Name = "Logs", Table = "TodoLog", Inverse = true)]
[Key(1, Column = "Todo")]
[OneToMany(2, ClassType = typeof(TodoLog)]
public virtual IEnumerable<TodoLog> Logs
{
get => logs;
protected set => log = (IList<TodoLog>)value;
}
}
TodoLog 的映射
[Class(NameType = typeof(TodoLog), Name = "TodoLog")]
public class TodoLog
{
[Id(-2, Name = "Id")]
[Generator(-1, Class = "native")]
public virtual long Id { get; set; }
[ManyToOne]
public virtual Todo Todo { get; set; }
[Property]
public virtual Enums.TodoAction Action { get; set; }
[ManyToOne]
public virtual User ExecutedBy { get; set; }
[Property]
public virtual DateTime ExectutedOn { get; set; }
}
======== 编辑 ========
当我将TodoLog 的所有代码放在注释中时,测试运行良好,但只要我将Class-attribute 添加到TodoLog,我就会收到与以前相同的错误。完全删除 TodoLog 并添加不同的类 TodoTest 会导致 TodoTest 出现相同的错误。
我还使用 .Net Reflector 来检查该类是否正确编译,但那里的一切似乎都很好。
在我运行测试时调试代码时,在加载包含TodoLog 的程序集时发生错误:
foreach(var a in projectsAssemblies)
{
Configuration.AddInputStream(HbmSerializer.Default.Serialize(a));
}
查看包含TodoLog 的程序集的属性ExportedTypes 时,TodoLog 类在该列表中。
【问题讨论】:
-
你能展示你是如何构建你的
SessionFactory的吗?
标签: c# sqlite nhibernate