When SqlSugar generating entity class, the table name spaces removed

Use sqlsugarproblem in generating a corresponding entity. Database, there are a few table name contains spaces, such as Order Detail, Customer Infolike, 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;
    }
}
Published 62 original articles · won praise 68 · views 160 000 +

Guess you like

Origin blog.csdn.net/ZUFE_ZXh/article/details/105052014