我想知道Josh Close的CsvHelper是否有任何配置我缺少将值转换为null.我是这个库的忠实粉丝,但我一直认为应该有某种配置让它知道你的文件中什么值代表NULL.一个例子是一个值为"NA","EMPTY","NULL"等的列.我确信我可以创建自己的TypeConverter,但我希望有一个更简单的选项来设置配置中的某个位置对于我遇到的文件,这往往相当普遍.
是否有相对容易的配置设置?
我在CsvHelper.TypeConversion命名空间中找到了TypeConversion,但我不知道在哪里应用这样的东西或正确用法的例子:
new NullableConverter(typeof(string)).ConvertFromString(new TypeConverterOptions(), "NA")
Run Code Online (Sandbox Code Playgroud)
我也在使用最新版本2.2.2
谢谢!
我一直试图弄清楚如何设置EF7(Beta 4)的小数精度没有运气.
我期待做类似的事情:
modelBuilder.Entity<SomeClass>().Property(p => p.DecimalProperty).Precision(10, 6)
Run Code Online (Sandbox Code Playgroud)
这似乎不可用,但我能够在GitHub的存储库中找到以下类:
没有使用RelationalTypeMapping类或方法签名的示例.也许这只是用作检索信息的映射api的一部分?
我可能期望的另一个地方是:
modelBuilder.Entity<SomeClass>().Property(p => p.DecimalProperty).ForRelational().ColumnType()
Run Code Online (Sandbox Code Playgroud)
要么
modelBuilder.Entity<SomeClass>().Property(p => p.DecimalProperty).ForSqlServer().ColumnType()
Run Code Online (Sandbox Code Playgroud)
这些只需要一个字符串,这个功能还没有实现,或者我只是没有找到正确的位置?
编辑:刚刚意识到字符串可能是.ColumnType("十进制(10,6)")类型的解决方案,直到进一步构建,仍然不介意得到一些澄清,因为我不希望使用字符串为此
编辑:在从bricelam澄清后,我最终创建了以下扩展以供使用,以避免使用字符串,我感谢他们的方法简单:
public static RelationalPropertyBuilder DecimalPrecision(this RelationalPropertyBuilder propertyBuilder, int precision, int scale)
{
return propertyBuilder.ColumnType($"decimal({precision},{scale})");
}
Run Code Online (Sandbox Code Playgroud)
用法示例:
modelBuilder.Entity<SomeClass>().Property(p => p.DecimalProperty).ForRelational().DecimalPrecision(10,6);
Run Code Online (Sandbox Code Playgroud)
编辑:对RC1进行修改
我还没有对它们进行过测试,但我只是将以下2个样本放在一起,这可能与RC1一样
public static PropertyBuilder DecimalPrecision(this PropertyBuilder propertyBuilder, string precision, string scale)
{
return propertyBuilder.HasColumnType($"decimal({precision},{scale})");
}
public static PropertyBuilder SqlDecimalPrecision(this PropertyBuilder propertyBuilder, string precision, string scale)
{
return propertyBuilder.ForSqlServerHasColumnType($"decimal({precision},{scale})");
}
Run Code Online (Sandbox Code Playgroud)
由于我还没有尝试过这个,我不确定"HasColumnType"或"ForSqlServerHasColumnType"之间的正确用法,但希望这会指向某个人正确的方向.
在先前版本的Entity Framework中,我一直在使用Effort(https://effort.codeplex.com/)进行单元测试.我决定为EF Core提供新的内存提供程序,并很快发现它不支持在OnModelCreating中设置的IsRequired()和其他实体配置.有没有办法让它尊重这种配置?如果没有,这是否在todo列表上实现?甚至可能是内存提供商的另类选择?
我希望能够使用测试步骤来交换上下文,并在一些可以利用相同代码的集成测试场景中使用真正的数据库.这似乎是"很高兴",也许这就是EF Core的努力.我找不到任何关于为EF Core工作的努力.
我在EF的Uservoice页面上找不到任何内容(https://data.uservoice.com/forums/72025-entity-framework-feature-suggestions),如果它不可用,它将会在那里找到.
我已经将多个数据库调用移到 EF Core 中,但我们没有在 Application Insights 捕获的依赖项的“数据”中显示任何查询。如果未捕获参数,这将是理想的,因此我们可以在“exec sp_executesql”内的查询上进行聚合。我们一直在获取对非 EF DB 访问的查询。这还没有为 EF Core 实现吗?
在EF 6.1中引入了映射API,最终我们可以访问表名和列名.获取表名是EF Core中一个非常好的变化,但我还没有发现如何获取列名.
对于这里感兴趣的人,我是如何获得最新版本的表名(RC1)
context.Model.FindEntityType(typeof(T)).SqlServer().TableName
Run Code Online (Sandbox Code Playgroud)
获取列名的当前方法是什么,或者这还没有?