第一步: 在Model.tt文件添加一个方法读取数据库中的字段说明
public string GetRemark(EdmProperty edmProperty){
//System.Diagnostics.Debugger.Launch();
var tableName = edmProperty.DeclaringType.Name;
var colName=_code.Escape(edmProperty);
//System.Diagnostics.Debugger.Break();
string sql = string.Format(@"SELECT
字段说明=isnull(props.[value],'')
FROM syscolumns cols
inner join sysobjects objs on cols.id= objs.id and objs.xtype='U' and objs.name<>'dtproperties'
left join sys.extended_properties props on cols.id=props.major_id and cols.colid=props.minor_id
where objs.name='{0}' and cols.name='{1}'",tableName,colName);
string sqlcon = "Data Source=192.168.1.102;User ID=sa;Password=123456;Initial Catalog=DTTT";
object remark=new object();
using(System.Data.SqlClient.SqlConnection conn = new System.Data.SqlClient.SqlConnection(sqlcon)){
conn.Open();
System.Data.SqlClient.SqlCommand cmd = new System.Data.SqlClient.SqlCommand(sql, conn);
r

本文介绍了如何在EF6.0中为实体类添加注释,通过修改Model.tt模板文件,实现从数据库读取字段说明并自动生成注释。
最低0.47元/天 解锁文章
3097

被折叠的 条评论
为什么被折叠?



