ConfORM Nhibernate OneToManyKeyColumnApplier 问题
我在我的一个 MVC 项目中使用 ConfORM Nhibernate。并且有一对多映射的问题。
IEnumerable<Type> domainEntities = this.GetDomainEntities();
var relationalMapper = new ObjectRelationalMapper();
relationalMapper.TablePerConcreteClass(domainEntities);
relationalMapper.Patterns.PoidStrategies.Add(new NativePoidPattern());
relationalMapper.Cascade<Category, Product>(Cascade.All);
relationalMapper.ManyToMany<Category, Product>();
relationalMapper.Cascade<Order, Product>(Cascade.Persist);
var mapper = new Mapper(relationalMapper);
var englishInflector = new EnglishInflector();
mapper.PatternsAppliers.Merge(new ClassPluralizedTableApplier(englishInflector));
mapper.PatternsAppliers.Merge(new OneToManyKeyColumnApplier(relationalMapper));
.....
HbmMapping mapping = mapper.CompileMappingFor(domainEntities);
订单和用户类:一个用户有多个订单。
public class Order : BaseEntity
{
public Order(User user)
{
if (user == null)
{
throw new ArgumentNullException("user");
}
this.User = user;
}
protected Order()
{
}
public virtual User User { get; protected set; }
}
和用户:
public class User : BaseEntity
{
public User()
{
this.Orders = new HashedSet<Order>();
}
public virtual string FirstName { get; set; }
public virtual ISet<Order> Orders { get; protected set; }
}
我期望这样的关系:Orders.UserId ->数据库中的 User.Id。但是当 Nhibernate 生成数据库时,我们遇到了这个问题(参见图片):
UPS。双引用User和UserId突然出现。当我们删除[用户]时,Nhivernate 无法对该表进行内部连接。双重时间令人悲伤: 列名“用户”无效。 列名“用户”无效。
我认为设置 ConfORM 存在一些问题。 如果我删除 mapper.PatternsAppliers.Merge(new OneToManyKeyColumnApplier(relationalMapper)); ConfORM 生成的只是 [User] 参考键。
有人知道这里有什么问题吗? 提前致谢。
I am using ConfORM Nhibernate in one of my MVC project. And had problem with One to Many Mappings.
IEnumerable<Type> domainEntities = this.GetDomainEntities();
var relationalMapper = new ObjectRelationalMapper();
relationalMapper.TablePerConcreteClass(domainEntities);
relationalMapper.Patterns.PoidStrategies.Add(new NativePoidPattern());
relationalMapper.Cascade<Category, Product>(Cascade.All);
relationalMapper.ManyToMany<Category, Product>();
relationalMapper.Cascade<Order, Product>(Cascade.Persist);
var mapper = new Mapper(relationalMapper);
var englishInflector = new EnglishInflector();
mapper.PatternsAppliers.Merge(new ClassPluralizedTableApplier(englishInflector));
mapper.PatternsAppliers.Merge(new OneToManyKeyColumnApplier(relationalMapper));
.....
HbmMapping mapping = mapper.CompileMappingFor(domainEntities);
And classes Order and User: One User had many Orders.
public class Order : BaseEntity
{
public Order(User user)
{
if (user == null)
{
throw new ArgumentNullException("user");
}
this.User = user;
}
protected Order()
{
}
public virtual User User { get; protected set; }
}
And Users:
public class User : BaseEntity
{
public User()
{
this.Orders = new HashedSet<Order>();
}
public virtual string FirstName { get; set; }
public virtual ISet<Order> Orders { get; protected set; }
}
I expect relations like this: Orders.UserId -> User.Id in the DB. But when the Nhibernate had genereted DB we had this problem (See image):
UPS. Double reference User and UserId suddenly uppeared. And when we removed [user] Nhivernate can`t do inner join this tables. It sad that double time:
Invalid column name 'User'.
Invalid column name 'User'.
I think there is some problems with setuping ConfORM.
If I remove mapper.PatternsAppliers.Merge(new OneToManyKeyColumnApplier(relationalMapper));
ConfORM generete just [User] reference key.
Anyone know what the problem is here?
Thanks in Advance.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您需要添加以下应用程序
可能是因为列名称已从用户端更改,但尚未从订单端更改。
You need to add the following applier
Probably thats because column name has changed from Users side, but has not changed from Order side.