表定义中的 Fluent Hibernate Automapping 问题(所有索引不为空)
标题:具有相同变量名称列表的多个类在表定义中存在问题(所有索引不为空)
假设我
public interface IInterface1
{
IList<string> myList {get; set;}
}
public class class1 : IInterface1
{
IList <string> myList {get; set;}
public class1()
{
myList = new List<string>();
}
}
public class class2 : IInterface1
{
IList<string> myList {get; set;}
public class2()
{
myList = new List<string>();
}
}
在创建表时从一个接口实现了两个类,对于 myList,表定义将类似于
- class1_id 'not null = true '
- value
- class2_id 'not null = true'
当您尝试保存一个值时,它将失败,因为它一次始终只有一个 id 值。
当仅保存 class1 时,只能保存 class1_id,而 class2_id 将为空,这将导致插入失败并出现错误
'could not insert collection:.....VALUES (?p0, ?p1)]'
Title: multiple class with same variable name list has issues in table definition (all indices not null)
lets say i have two class implementing from one interface
public interface IInterface1
{
IList<string> myList {get; set;}
}
public class class1 : IInterface1
{
IList <string> myList {get; set;}
public class1()
{
myList = new List<string>();
}
}
public class class2 : IInterface1
{
IList<string> myList {get; set;}
public class2()
{
myList = new List<string>();
}
}
when the table is created the for myList the table definition would be like
- class1_id 'not null = true'
- value
- class2_id 'not null = true'
when you try to save a value it will fail since it will always have only one id value at a time.
when class1 is saved only only class1_id can be saved and class2_id will be empty this would cause the insert to fail with error
'could not insert collection:.....VALUES (?p0, ?p1)]'
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论