从坏表列中命名C#类

bar*_*oma 5 c# entity-framework

到目前为止,我已经使用了Entity Framework和SQL Server数据库.所以我可以将我的表名称表示为类名和属性名称,如下所示.

class Product{ 
      public string Id { get; set;} 
      public string Name { get; set;} 
}
Run Code Online (Sandbox Code Playgroud)

表名和列名与我的班级相同.

但现在我将使用Postgresql数据库工作.表名和列名是这样的.

  • 表格products,product_categories(小写)
  • 专栏product_id, product_name, category_id,......

所以我不想使用这样的类名:

class products { 
      public string product_id { get; set; }
      public string product_name { get; set; }
      public string category_id { get; set; }
}
Run Code Online (Sandbox Code Playgroud)

这看起来像一个丑陋的命名约定.我该如何解决这个问题?

mas*_*son 6

使用表和列属性.从MSDN示例:

[Table("InternalBlogs")]
public class Blog
{   
    [Column("BlogDescription", TypeName="ntext")]
    public String Description {get;set;}
}
Run Code Online (Sandbox Code Playgroud)