Closed 12500540 closed 2 years ago
应该是这样写的吧
//属性:新重载 完全自定义用配置
.SettingPropertyTemplate((columns,temp,type) => {
var columnattribute = "\r [SugarColumn({0})]";
List<string> attributes = new List<string>();
if (columns.IsPrimarykey)
attributes.Add("IsPrimaryKey=true");
if (columns.IsIdentity)
attributes.Add("IsIdentity=true");
if (attributes.Count == 0)
{
columnattribute = "";
}
return temp.Replace("{PropertyType}", type)
.Replace("{PropertyName}", columns.DbColumnName)
.Replace("{SugarColumn}",string.Format(columnattribute,string.Join(",", attributes)));
})
.CreateClassFile("c:\\Demo\\7");
应该是这样写的吧
//属性:新重载 完全自定义用配置 .SettingPropertyTemplate((columns,temp,type) => { var columnattribute = "\r [SugarColumn({0})]"; List<string> attributes = new List<string>(); if (columns.IsPrimarykey) attributes.Add("IsPrimaryKey=true"); if (columns.IsIdentity) attributes.Add("IsIdentity=true"); if (attributes.Count == 0) { columnattribute = ""; } return temp.Replace("{PropertyType}", type) .Replace("{PropertyName}", columns.DbColumnName) .Replace("{SugarColumn}",string.Format(columnattribute,string.Join(",", attributes))); }) .CreateClassFile("c:\\Demo\\7");
是的。是官网demo代码的小bug
什么BUG我一直没有明白,我这边测试都正常 你可以加我 qq 610262374 细说
db.DbFirst //类 .SettingClassTemplate(old => { return old;/修改old值替换/ }) //类构造函数 .SettingConstructorTemplate(old => { return old;/修改old值替换/ }) .SettingNamespaceTemplate(old => { return old + "\r\nusing SqlSugar;"; //追加引用SqlSugar }) //属性备注 .SettingPropertyDescriptionTemplate(old => { return old;/修改old值替换/})
//属性:新重载 完全自定义用配置
.SettingPropertyTemplate((columns, temp, type) => {
var columnattribute = "\r\n [SugarColumn({0})]";
List<string> attributes = new List<string>();
if (columns.IsPrimarykey)
attributes.Add("IsPrimaryKey=true");
if (columns.IsIdentity)
attributes.Add("IsIdentity=true");
if (attributes.Count == 0)
{
columnattribute = "";
}
return temp.Replace("{PropertyType}", type)
.Replace("{PropertyName}", columns.DbColumnName)
.Replace("{SugarColumn}", string.Format(columnattribute, string.Join(",", attributes)));
})
.CreateClassFile("c:\\Demo\\8");
根据dotnet5提供的新DEMO,可以完美解决遇到的两个问题,我认为可以Close这个issues了。
.SettingPropertyTemplate((columns, temp, type) => //属性:新重载 完全自定义用配置 { var columnattribute = "\r [SugarColumn({0})]";//此处代码生成数据实体有问题 List attributes = new List();
if (columns.IsPrimarykey)
attributes.Add("IsPrimaryKey=true");
if (columns.IsIdentity)
attributes.Add("IsIdentity=true");
if (attributes.Count == 0)
{
columnattribute = "";
}
return temp.Replace("{PropertyType}", type)
.Replace("{PropertyName}", columns.DbColumnName)
.Replace("{SugarColumn}", string.Format(columnattribute, string.Join(",", attributes)));
})
复盘环境:
1、IDE是VS2022@17.1.3版
2、插件是SqlSugarCore@5.0.7.8版
3、类库是NET6框架
解决方案:
var columnattribute = "\r\n [SqlSugar.SugarColumn({0})]"; //使用此代码替换原代码即可解决问题
前提:
models类库已经nuget了SqlSugarCore或SqlSugar,根据coer或Freamwork框架而定
分析:
问题1:可能是VS2022 中文版换行必须使用 \r\n
问题2:引用空间问题,目前没办法找到上级节点,否则直接使用 using.SqlSugar 方式解决最完美,在属性上使用有点冗余代码