mirror of
https://gitee.com/dotnetchina/SqlSugar.git
synced 2025-09-19 18:22:23 +08:00
Add demo
This commit is contained in:
58
Src/Asp.NetCore2/MySqlTest/UserTestCases/Models/Account.cs
Normal file
58
Src/Asp.NetCore2/MySqlTest/UserTestCases/Models/Account.cs
Normal file
@@ -0,0 +1,58 @@
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
using SqlSugar;
|
||||
|
||||
namespace WebApplication4
|
||||
{
|
||||
/// <summary>
|
||||
/// 账号信息
|
||||
/// </summary>
|
||||
[SugarTable("account")]
|
||||
public class Account
|
||||
{
|
||||
/// <summary>
|
||||
/// 账号Id
|
||||
/// </summary>
|
||||
[SugarColumn(ColumnName = "id", IsPrimaryKey = true, IsIdentity = true)]
|
||||
public int Id { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 登录账号
|
||||
/// </summary>
|
||||
[SugarColumn(ColumnName = "user_name", Length = 50)]
|
||||
public string UserName { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 登录密码
|
||||
/// </summary>
|
||||
[SugarColumn(ColumnName = "password", Length = 50)]
|
||||
public string Password { get; set; }
|
||||
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 账号角色类型
|
||||
/// </summary>
|
||||
public enum RoleType
|
||||
{
|
||||
[Display(Name = "匿名")]
|
||||
Anonymous = -1,
|
||||
|
||||
[Display(Name = "管理员")]
|
||||
Admin = 0,
|
||||
|
||||
[Display(Name = "客服")]
|
||||
Employee = 1,
|
||||
|
||||
[Display(Name = "企业")]
|
||||
Company = 2,
|
||||
|
||||
[Display(Name = "坐席")]
|
||||
User = 3,
|
||||
|
||||
[Display(Name = "渠道")]
|
||||
Partner = 4,
|
||||
|
||||
[Display(Name = "代理")]
|
||||
Agent = 5,
|
||||
}
|
||||
}
|
38
Src/Asp.NetCore2/MySqlTest/UserTestCases/Models/Admin.cs
Normal file
38
Src/Asp.NetCore2/MySqlTest/UserTestCases/Models/Admin.cs
Normal file
@@ -0,0 +1,38 @@
|
||||
using SqlSugar;
|
||||
|
||||
namespace WebApplication4
|
||||
{
|
||||
/// <summary>
|
||||
/// 管理员信息
|
||||
/// </summary>
|
||||
[SugarTable("admin")]
|
||||
[SugarIndex("index_admin_account_id", nameof(AccountId), OrderByType.Asc )]
|
||||
public class Admin
|
||||
{
|
||||
/// <summary>
|
||||
/// Id
|
||||
/// </summary>
|
||||
[SugarColumn(ColumnName = "id", IsPrimaryKey = true, IsIdentity = true)]
|
||||
public int Id { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 关联账号
|
||||
/// </summary>
|
||||
[SugarColumn(ColumnName = "account_id")]
|
||||
public int AccountId { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 姓名
|
||||
/// </summary>
|
||||
[SugarColumn(ColumnName = "name", Length = 50)]
|
||||
public string Name { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 手机号码
|
||||
/// </summary>
|
||||
[SugarColumn(ColumnName = "mobile", IsNullable = true, Length = 20)]
|
||||
public string Mobile { get; set; }
|
||||
|
||||
}
|
||||
|
||||
}
|
@@ -31,6 +31,7 @@ namespace OrmTest
|
||||
}
|
||||
public static void Init()
|
||||
{
|
||||
Unitsdfasfasa.Init();
|
||||
Unitdfsdyss.Init();
|
||||
Unitadfasfafays.Init();
|
||||
Unitadfa12.Init();
|
||||
|
@@ -0,0 +1,47 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace OrmTest
|
||||
{
|
||||
using System.Reflection;
|
||||
using SqlSugar;
|
||||
|
||||
internal class Unitsdfasfasa
|
||||
{
|
||||
public static void Init()
|
||||
{
|
||||
var db = NewUnitTest.Db;
|
||||
|
||||
var types = Assembly.GetExecutingAssembly().GetTypes()
|
||||
.Where(type => !type.IsGenericType)
|
||||
.Where(s=>s.Namespace== "WebApplication4")
|
||||
.Where(type => !type.IsInterface)
|
||||
.Where(type => !type.IsAbstract)
|
||||
.Where(type => IntrospectionExtensions.GetTypeInfo(type).IsClass)
|
||||
.Where(type => type.GetCustomAttribute<SqlSugar.SugarTable>() != null)
|
||||
.ToArray();
|
||||
|
||||
#region 问题复现,报错不够清楚,不知道哪个实体有问题
|
||||
//var diffString2 = db.CodeFirst.GetDifferenceTables(types).ToDiffString();
|
||||
#endregion
|
||||
|
||||
#region 问题复现
|
||||
foreach (var type in types)
|
||||
{
|
||||
try
|
||||
{
|
||||
var diffString = db.CodeFirst.GetDifferenceTables(type).ToDiffString();
|
||||
db.CodeFirst.InitTables(type);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Console.WriteLine($"type = {type.Name} 错误: {ex}");
|
||||
}
|
||||
}
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user