下面是用Entity Framework Power Tools 成生的代码
public partial class Feature
{
public int FeatureID { get; set; }
public string FeatureName { get; set; }
}public class FeatureMap : EntityTypeConfiguration<Feature>
{
public FeatureMap()
{
// Primary Key
this.HasKey(t => t.FeatureID); // Properties
this.Property(t => t.FeatureName)
.IsRequired()
.HasMaxLength(50); // Table & Column Mappings
this.ToTable("Feature");
this.Property(t => t.FeatureID).HasColumnName("FeatureID");
this.Property(t => t.FeatureName).HasColumnName("Feature"); }
}
大家看到this.Property(t => t.FeatureName).HasColumnName("Feature"); 这一行了没?我数据库中有个表名叫Feature,这张表里有个字段也叫Feature,结果在Entity Framework中运行时报错为
Feature: Name: Name 'Feature' cannot be used in type 'CodeFirstDatabaseSchema.Feature'. Member names cannot be the same as their enclosing type.请问有没有什么解决办法?数据库字段名是不可能改了!因为多套系统已经在使用了.Entity Framework
public partial class Feature
{
public int FeatureID { get; set; }
public string FeatureName { get; set; }
}public class FeatureMap : EntityTypeConfiguration<Feature>
{
public FeatureMap()
{
// Primary Key
this.HasKey(t => t.FeatureID); // Properties
this.Property(t => t.FeatureName)
.IsRequired()
.HasMaxLength(50); // Table & Column Mappings
this.ToTable("Feature");
this.Property(t => t.FeatureID).HasColumnName("FeatureID");
this.Property(t => t.FeatureName).HasColumnName("Feature"); }
}
大家看到this.Property(t => t.FeatureName).HasColumnName("Feature"); 这一行了没?我数据库中有个表名叫Feature,这张表里有个字段也叫Feature,结果在Entity Framework中运行时报错为
Feature: Name: Name 'Feature' cannot be used in type 'CodeFirstDatabaseSchema.Feature'. Member names cannot be the same as their enclosing type.请问有没有什么解决办法?数据库字段名是不可能改了!因为多套系统已经在使用了.Entity Framework
解决方案 »
- C#中如何使用DES对zip文件加密???
- IrisSkin2.dll使用方法?
- 高分求解,链接的MHT文件为中文名时,链接里的图表出错显示不了
- adapter.Update()违反并发性
- 自己做了个公司内部浏览器,在弹出窗口时候是搜狗,360,一样!而不是IE那样新开个窗口,请问怎么解决?
- 大家认为C#中序列化比Java简单吗?
- 【求助】 关于datatable,text控件的databinding问题
- 一个很简单的问题:请各位熟悉Datagrid控件的高手帮帮我~~~
- 怎么样在两个winform窗体传递值!?
- Winform Custor 显示手图标?
- C#的DropDownList问题
- 关于.net学习的困惑
this.Property(t => t.FeatureName).HasColumnName("Feature.Feature");
哥们用你这方法解决了.我是这样写的dbo.Feature.Feature感谢.