FluentNHibernate Component.ColumnPrefix 未应用

发布于 2024-11-14 08:11:25 字数 1294 浏览 1 评论 0原文

我最近将 FluentNHibernatev1.1.0.685 升级到 v1.2.0.712(最新),适用于 NHibernate 2.1

我的问题似乎与使用 Component().ColumnPrefix() 映射的类有关。

例如,

 public class Address{ 
    public string Street {get; set;} 
    public string Zip {get; set;} 
 } 

 public class AddressMap : ComponentMap<Address>{
     Map( x => x.Street );
     Map( x => x.Zip );
 }

 public class PersonMap : ClassMap<Person> 
 { 
    public PersonMap(){ 

       Id( x => x.Id ); 

       Map( x=> x.Name ); 

       Component( x => x.Address ) 
          .ColumnPrefix("ADDRESS_"); 
    } 
 } 

人员表

  Id       Name        ADDRESS_Street     ADDRESS_Zip
 ----------------------------------------------------
  1        Brian       123 Example St.    12345

FNH v1.1.0.685 中的

行为“ADDRESS_” 前缀正确应用于地址组件的属性。

FNH v1.2.0.712(最新)中的行为

“ADDRESS_” 前缀不再应用于地址组件的属性。 NHiberante 生成上表中未命名的“Street”和“Zip”列。


如果有人有任何见解,我将不胜感激。我开始认为这可能是一个错误。

谢谢,
布莱恩

I recently upgraded FluentNHibernate from v1.1.0.685 to v1.2.0.712 (latest) for NHibernate 2.1.

My issue appears to be with classes that use the Component().ColumnPrefix() mapping.

For example,

 public class Address{ 
    public string Street {get; set;} 
    public string Zip {get; set;} 
 } 

 public class AddressMap : ComponentMap<Address>{
     Map( x => x.Street );
     Map( x => x.Zip );
 }

 public class PersonMap : ClassMap<Person> 
 { 
    public PersonMap(){ 

       Id( x => x.Id ); 

       Map( x=> x.Name ); 

       Component( x => x.Address ) 
          .ColumnPrefix("ADDRESS_"); 
    } 
 } 

Person Table

  Id       Name        ADDRESS_Street     ADDRESS_Zip
 ----------------------------------------------------
  1        Brian       123 Example St.    12345

Behavior in FNH v1.1.0.685

The "ADDRESS_" prefix is correctly applied to the properties of the Address component.

Behavior in FNH v1.2.0.712 (latest)

The "ADDRESS_" prefix is no longer applied to the properties of the Address component. NHiberante generates "Street" and "Zip" columns which are not named in table above.


I'd appreciate if anyone has any insight. I'm beginning to think this might be a bug.

Thanks,
Brian

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(3

把人绕傻吧 2024-11-21 08:11:25

@Brian,

几周前我遇到了确切的障碍。我正在使用自动映射,并通过创建组件属性约定来解决它:

Public Class ComponentPropertyConvention
    Implements IPropertyConvention, IPropertyConventionAcceptance

    Public Sub Accept(ByVal criteria As IAcceptanceCriteria(Of IPropertyInspector)) Implements IConventionAcceptance(Of IPropertyInspector).Accept
       criteria.Expect(Function(inspector) inspector.EntityType.Namespace.EndsWith("Components"))
    End Sub

    Public Sub Apply(ByVal instance As IPropertyInstance) Implements IConvention(Of IPropertyInspector, IPropertyInstance).Apply
        instance.Column(String.Format("{0}_{1}", New String() {instance.EntityType.Name.ToLower(), instance.Property.Name.Dbize()}))
    End Sub

End Class

可能有很多方法来实现您的接受标准,所以如果不适合,请不要遵循我的...

干杯

@Brian,

I hit the exact roadblock a few weeks ago. I'm using automappings and got around it by creating a Component Property Convention:

Public Class ComponentPropertyConvention
    Implements IPropertyConvention, IPropertyConventionAcceptance

    Public Sub Accept(ByVal criteria As IAcceptanceCriteria(Of IPropertyInspector)) Implements IConventionAcceptance(Of IPropertyInspector).Accept
       criteria.Expect(Function(inspector) inspector.EntityType.Namespace.EndsWith("Components"))
    End Sub

    Public Sub Apply(ByVal instance As IPropertyInstance) Implements IConvention(Of IPropertyInspector, IPropertyInstance).Apply
        instance.Column(String.Format("{0}_{1}", New String() {instance.EntityType.Name.ToLower(), instance.Property.Name.Dbize()}))
    End Sub

End Class

There's probably a wealth of ways to implement your acceptance criteria so don't follow mine if it doesnt suit...

Cheers

寂寞笑我太脆弱 2024-11-21 08:11:25

在研究了源代码中的单元测试之后;就我而言,我的约定在 FNH v1.1FNH v1.2 之间的应用似乎有所不同。

我认为发生的事情是这样的:

  1. My AddressMap : ComponentMap

    将被执行(这里没有问题)。

  2. 我的 PersonMap : ClassMap 将使用以下方式映射组件:

    Component( x => x.Address ).ColumnPrefix("ADDRESS_"); 
    

    来自步骤 1。

  3. 我的 FNH MyPropertyConvention 将调用:

    公共类 MyPropertyConvention :IPropertyConvention
    {
        公共无效应用(IPropertyInstance实例)
        {
            实例.Column(实例.名称); //这个调用是破坏性的
                                              //FNH v1.2 中的 ColumnPrefix()
        }
    }
    

它出现:

  • FNH v1.1< 调用 instance.Column() 时,步骤 3 对列前缀不会造成破坏。

  • FNH v1.2 中,步骤 3 对之前设置的任何 ColumnPrefix() 具有破坏性,并且会覆盖整个 列名称(包括前缀)。

因此,我使用 IPropertyConventionAcceptance 清理了 FNH 1.2 的约定,并小心调用 instance.Column(instance.Name) [现在调用对列前缀具有破坏性]。

感谢大家的帮助,
布莱恩

After investigating the unit tests in the source code; it appears that, in my case, my conventions were being applied differently between FNH v1.1 and FNH v1.2.

I think this is what happened:

  1. My AddressMap : ComponentMap<Address> would get executed (no problem here).

  2. My PersonMap : ClassMap<Person> would map a component using:

    Component( x => x.Address ).ColumnPrefix("ADDRESS_"); 
    

    from Step 1.

  3. My FNH MyPropertyConvention would call:

    public class MyPropertyConvention : IPropertyConvention
    {
        public void Apply( IPropertyInstance instance )
        {
            instance.Column( instance.Name ); //this call is destructive
                                              //to ColumnPrefix() in FNH v1.2
        }
    }
    

It appears:

  • in FNH v1.1, Step 3 is not destructive to the column prefix when calling instance.Column().

  • in FNH v1.2, Step 3 is destructive to any ColumnPrefix() previously set and over-writes the entire column name (including the prefix).

So, I cleaned up my conventions for FNH 1.2 using IPropertyConventionAcceptance being careful about my calls to instance.Column(instance.Name) [now that calls are destructive to column prefixes].

Thanks for everyone's help,
Brian

梦幻的心爱 2024-11-21 08:11:25

您需要创建一个 ComponentMap

类才能应用 ColumnPrefix

请参阅此处: http://wiki. Fluentnhibernate.org/Fluent_mapping#ComponentMap.3CT.3E< /a>

You need to create a ComponentMap<Address> class in order for the ColumnPrefix to be applied.

See here: http://wiki.fluentnhibernate.org/Fluent_mapping#ComponentMap.3CT.3E

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