我想创建一个约定,其中 EF 可以序列化为IEnumerable<String>
一种格式(比如逗号分隔值)并将它们存储在一个列中,并在将它们取回时IEnumerable<String>
再次创建一个。
msdn 链接http://msdn.microsoft.com/en-us/data/jj819164.aspx提到了以下示例
class DateTimeColumnTypeConvention : IConfigurationConvention<PropertyInfo, DateTimePropertyConfiguration>
{
public void Apply(
PropertyInfo propertyInfo, Func<DateTimePropertyConfiguration> configuration)
{
// If ColumnType hasn't been configured...
if (configuration().ColumnType == null)
{
configuration().ColumnType = "datetime2";
}
}
}
但我需要类似的东西
class DateTimeColumnTypeConvention : IConfigurationConvention<PropertyInfo, IEnumerable<string>>
{
public void Apply(PropertyInfo propertyInfo, Func<IEnumerable<string>> configuration)
{
// Get all the values of the property here, create a comma separated string ,ask EF to store this string by setting the ColumnType to varchar and then get it back.
}
}
我找不到任何明显的方法来做到这一点。有任何想法吗 ?