I have used Entity Framework and a SQL Server database until now. So I can represent my table name as a class name and property names as properties like following.
class Product{
public string Id { get; set;}
public string Name { get; set;}
}
The table and column names are the same with my class.
But now I will work a project that uses a Postgresql database. Table names and column names are like this.
products
, product_categories
(lowercase)product_id, product_name, category_id
, ....So I do not want to use class names like this:
class products {
public string product_id { get; set; }
public string product_name { get; set; }
public string category_id { get; set; }
}
This looks like an ugly naming conventions. How can I solve this issue?
Naming Conventions rules for Variables and Methods (Functions) are: It should begin with an alphabet. There may be more than one alphabet, but without any spaces between them. Digits may be used but only after alphabet.
Camel case for class names or lowercase+underscores (camel case is more common in my experience). Structs are used rarely (and typically because a library requires them, otherwise you'd use classes).
One popular convention is that leading capital letter CamelCase is used for the names of structs and classes, while normal camelCase is used for the names of functions and variables (although sometimes variables are written in c-style to make the visual separation between functions and variables more clear).
Use table and column attributes. From MSDN example:
[Table("InternalBlogs")]
public class Blog
{
[Column("BlogDescription", TypeName="ntext")]
public String Description {get;set;}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With