I am using the EF toolkit to create my POCO classes from an existing database. As the project proceeds I will have to generate this classes several times. The generated classes have some problems I do not want to have to correct every time generate the code.
Problem 1:
It does not generate good property names when a table has tow foreign keys to the same table. Example:
It generates:
public partial class Flow
{
public virtual Element Element { get; set; }
public virtual Element Element1 { get; set; }
}
when I wanted:
public partial class Flow
{
public virtual Element FromElement { get; set; }
public virtual Element ToElement { get; set; }
}
This I solved by using partial classes like that:
public partial class Flow
{
public virtual Element FromElement
{
get {return Element;}
set { Element = value; }
}
public virtual Element ToElement
{
get {return Element1;}
set {Element1=value;}
}
}
This way I do not have to edit the generated classes.
Second Problem:
it does not recognize auto increment GUID properties on the database. It generates:
public partial class Process
{
public System.Guid ProcessId { get; set; }
}
When it should generate:
public partial class Process
{
[DatabaseGenerated(DatabaseGeneratedOption.Identity)]
public System.Guid ProcessId { get; set; }
}
Question is, How to I tell EF that these columns are autoincrement without having to insert
"[DatabaseGenerated(DatabaseGeneratedOption.Identity)]" before each primary key field on the generated classes?