我想利用EF6自定义复数的新功能。我搜索了整个交互,但找不到合适的例子。
我从数据库(SQL Server)生成模型,并使用自定义T4模板生成上下文和模型类。
据我所知,我应该能够创建一个继承自DbConfiguration的类,并将其放在模型项目中。我做到了。
Public Class CustomConfiguration
Inherits DbConfiguration
Public Sub New()
MyBase.New()
SetPluralizationService(New CustomPluralizationService)
End Sub
End Class
此类引用CustomPluralizationService,我理解必须实现IPluralizationService。好又花花公子:
Imports System.Data.Entity.Infrastructure.Pluralization
Public Class CustomPluralizationService
Implements IPluralizationService
Public Function Pluralize(word As String) As String Implements System.Data.Entity.Infrastructure.Pluralization.IPluralizationService.Pluralize
End Function
Public Function Singularize(word As String) As String Implements System.Data.Entity.Infrastructure.Pluralization.IPluralizationService.Singularize
End Function
End Class
当然我应该完成Pluralize和Singularize函数的实现,但是我不知道究竟是怎么做的,因为我无法用任何语言在任何地方找到完整的例子。有人可以帮忙吗?
MSDN上的文档有这样的神秘垃圾:
Function Pluralize ( _
word As [%$TOPIC/dn176961_en-us_VS_113_3_0_0_0_0%] _
) As [%$TOPIC/dn176961_en-us_VS_113_3_0_0_0_1%]
Dim instance As [%$TOPIC/dn176961_en-us_VS_113_3_0_1_0_0%]
Dim word As [%$TOPIC/dn176961_en-us_VS_113_3_0_1_0_1%]
Dim returnValue As [%$TOPIC/dn176961_en-us_VS_113_3_0_1_0_2%]
returnValue = instance.Pluralize(word)
[%$TOPIC/dn176961_en-us_VS_113_3_0_2_0_0%] Pluralize(
[%$TOPIC/dn176961_en-us_VS_113_3_0_2_0_1%] word
)
[%$TOPIC/dn176961_en-us_VS_113_3_0_3_0_0%]^ Pluralize(
[%$TOPIC/dn176961_en-us_VS_113_3_0_3_0_1%]^ word
)