Use sqlsugar
problem in generating a corresponding entity. Database, there are a few table name contains spaces, such as Order Detail
, Customer Info
like, generated when the corresponding entity class, the name also has a space, which is illegal in C # class naming, so here take notes, remove the corresponding table space in a name
/// <summary>
/// 数据初始化
/// </summary>
/// <returns></returns>
public ActionResult DnInit()
{
string path = @"c:\DbEntities"; //保存路径
string nameSpace = "Entities"; //命名空间
try
{
SqlSugarClient db = new DbContext().Db; //SqlSugarClient对象
List<DbTableInfo> dbTables = new List<DbTableInfo>();
dbTables.AddRange(db.DbMaintenance.GetTableInfoList()); //表
dbTables.AddRange(db.DbMaintenance.GetViewInfoList()); //视图
//遍历
foreach (var item in dbTables)
{
//添加表映射
db.MappingTables.Add(item.Name.Replace(" ", string.Empty), item.Name);
}
db.DbFirst.IsCreateAttribute().IsCreateDefaultValue().CreateClassFile(path, nameSpace);
return View("success" as object);
}
catch (Exception)
{
throw;
}
}