ConfORM Nhibernate OneToManyKeyColumnApplier 问题

发布于 2024-10-05 04:34:08 字数 2008 浏览 3 评论 0原文

我在我的一个 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):

table structure

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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

來不及說愛妳 2024-10-12 04:34:08

您需要添加以下应用程序

mapper.PatternsAppliers.Merge(new ManyToOneColumnApplier());

可能是因为列名称已从用户端更改,但尚未从订单端更改。

You need to add the following applier

mapper.PatternsAppliers.Merge(new ManyToOneColumnApplier());

Probably thats because column name has changed from Users side, but has not changed from Order side.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文