0

因为可以找到关于 VB.Net 和 (Fluent) NHibernate 的信息非常少,所以我决定将这个问题写给所有其他正在寻找更多信息的开发人员。

我不得不努力解决的一件事是如何忽略 NHibernate 中的属性。

我不得不忽略属性的原因是因为我们使用了不能序列化接口类 (IList) 的 Web 服务。NHibernate 经常使用它。

所以我们不得不忽略 NHibernate 的一些属性,让这些属性将 IList 对象转换为可以在 Webservice 中使用的 List 对象。

我们找不到从这个 C# 代码到 VB.Net 的任何好的翻译:

.Override<Shelf>(map =>  
{  
  map.IgnoreProperty(x => x.YourProperty);
});

或者

.OverrideAll(map =>  
{  
  map.IgnoreProperty("YourProperty");
});

并找到了解决问题的不同解决方案(见自制答案)

4

1 回答 1

0

创建一个实现 DefaultAutomappingConfiguration 的新类

Imports FluentNHibernate.Automapping

Public Class AutomapperConvention
    Inherits DefaultAutomappingConfiguration

    Public Overrides Function ShouldMap(ByVal member As FluentNHibernate.Member) As Boolean
        'When the the mapper finds a List object it ignores the mapping you can make your own choices here'
        If (member.PropertyType.IsGenericType AndAlso Not (member.PropertyType.IsInterface)) Then
            Return False
        Else
            Return MyBase.ShouldMap(member)
        End If
    End Function

End Class

在此处添加 AutomapperConvention:

'Custom automapping to make the automapper find the correct id's (entityname + "Id")
Dim mappingConfig As New AutomapperConvention()
Dim model As New FluentNHibernate.Automapping.AutoPersistenceModel(mappingConfig)
于 2010-07-29T13:00:41.310 回答