如何自动生成 class 字段注释到数据库? Entity Framework 先上代码
How to auto-generate class field comment to database? Entity Framework code first
我正在使用 Entity Framework 代码优先模式,但如何自动生成 class 字段注释到数据库?
示例:
[Table("User")]
public class User
{
/// <summary>
/// Id
/// </summary>
public long Id{get;set;}
/// <summary>
/// this is name
/// </summary>
public string name{get;set;}
}
SQL应该是这样的:
CREATE TABLE User
(
id BIGINT(20) NOT NULL AUTO_INCREMENT COMMENT 'Id',
name VARCHAR(128) NOT NULL COMMENT 'this is name'
)
有人知道如何实现吗?
除了"not."在评论中给出更具体的答案。
这基本上是不可能实现的,因为注释不会传递给作为生成迁移元素基础的编译对象。
此外,考虑到免费评论部分可能包含可以用作书籍的评论(即评论没有限制,但数据库中有评论)。
您可以考虑使用可能适合您需要的新属性,例如:
[DbComment('This field is containing bla bla')]
public int FooBar {get; set;}
然后可以通过覆盖 Sql-生成 类 将其合并到数据库生成过程中。
使用这种方法的问题仍然是评论需要维护两次。
我正在使用 Entity Framework 代码优先模式,但如何自动生成 class 字段注释到数据库?
示例:
[Table("User")]
public class User
{
/// <summary>
/// Id
/// </summary>
public long Id{get;set;}
/// <summary>
/// this is name
/// </summary>
public string name{get;set;}
}
SQL应该是这样的:
CREATE TABLE User
(
id BIGINT(20) NOT NULL AUTO_INCREMENT COMMENT 'Id',
name VARCHAR(128) NOT NULL COMMENT 'this is name'
)
有人知道如何实现吗?
除了"not."在评论中给出更具体的答案。
这基本上是不可能实现的,因为注释不会传递给作为生成迁移元素基础的编译对象。
此外,考虑到免费评论部分可能包含可以用作书籍的评论(即评论没有限制,但数据库中有评论)。
您可以考虑使用可能适合您需要的新属性,例如:
[DbComment('This field is containing bla bla')]
public int FooBar {get; set;}
然后可以通过覆盖 Sql-生成 类 将其合并到数据库生成过程中。
使用这种方法的问题仍然是评论需要维护两次。