我的类库项目引用Entity Framework 5程序集。下面的代码中“AvailablePoints”的.NET类型为Decimal。我正在尝试使用CodeFirst Fluent API配置将此属性映射到SQL Server中的十进制(9,4)数据类型,以便数据项不会在2个小数位处被截断,这是默认映射。
protected override void OnModelCreating(DbModelBuilder modelBuilder)
{
modelBuilder.Entity<EventGroup>().Property(g => g.AvailablePoints).HasPrecision(9,4);
base.OnModelCreating(modelBuilder);
}
"The type 'System.Data.Spatial.DbGeography' is defined in an assembly that is not referenced. You must add a reference to assembly 'System.Data.Entity, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089'.
.Property(g => g.AvailablePoints).HasPrecision(9,4);
,它将编译良好。 EF5文档或论坛帖子均未解决此编译器错误,也未解释此Fluent API配置与System.Data.Spatial.DbGeography
类型如何相关。
最佳答案
这是因为您的项目没有引用所需的程序集。
在解决方案资源管理器中,找到项目中的“References”文件夹。
右键单击该文件夹,然后单击“添加引用”。
在“.NET”选项卡中,可以找到带有4.0.0.0版的“System.Data.Entity”条目。添加该内容可以解决此问题。
https://stackoverflow.com/questions/15182315/
相关文章:
perl - 无法编译我的 perl 脚本。让一切正常工作的最简单方法是什么?
android - 生成的渲染脚本文件导致 “Invalid unicode”错误
compiler-construction - 未定义对ruserok错误的引用
visual-c++ - 如何针对VES2008编译Greta?
android - 如何解决java.lang.NoClassDefFoundError
android - 如何解决Java Eclipse中的 “The hierarchy of the
android - Android “The specified child already has
asp.net - asp.net C#编译器错误CS1061