I'm using Entity Framework code-first mode, but how to auto-generate class field comments to database?
Example:
[Table("User")]
public class User
{
/// <summary>
/// Id
/// </summary>
public long Id{get;set;}
/// <summary>
/// this is name
/// </summary>
public string name{get;set;}
}
SQL should be like this:
CREATE TABLE User
(
id BIGINT(20) NOT NULL AUTO_INCREMENT COMMENT 'Id',
name VARCHAR(128) NOT NULL COMMENT 'this is name'
)
Does anyone have an idea how to achieve this?
To give a more specific answer besides "not." in the comments.
It's basically not possible to achieve this as comments are not passed over to the compiled object that is taken as the base for generating the migration elements.
In addition consider that the free comment section might contain a comment that might be used as a book (i.e. there's no limitation on comments but there is on comments in the database).
You might consider using a new attribute that might suit your needs, like:
[DbComment('This field is containing bla bla')]
public int FooBar {get; set;}
This might then be incorporated into the database generation process by overwriting the Sql-Generation classes.
The concern by using this approach is still that comments need to be maintained twice.