mirror of
https://github.com/dotnetcore/FreeSql.git
synced 2026-02-23 08:40:56 +08:00
update
35
CodeFirst.md
35
CodeFirst.md
@@ -128,26 +128,16 @@ var t2 = fsql.CodeFirst.SyncStructure<Topic>();
|
||||
1.扫描 IEntity类所在程序集,反射得到类上有特性标签为TableAttribute 的所有类,该方法需在实体类上指定了 [Table(Name = "xxx")]特性标签
|
||||
|
||||
```c#
|
||||
public class ReflexHelper
|
||||
public static Type[] GetTypesByTableAttribute()
|
||||
{
|
||||
public static Type[] GetTypesByTableAttribute()
|
||||
{
|
||||
List<Type> tableAssembies = new List<Type>();
|
||||
foreach (Type type in Assembly.GetAssembly(typeof(IEntity)).GetExportedTypes())
|
||||
{
|
||||
foreach (Attribute attribute in type.GetCustomAttributes())
|
||||
{
|
||||
if (attribute is TableAttribute tableAttribute)
|
||||
{
|
||||
if (tableAttribute.DisableSyncStructure == false)
|
||||
{
|
||||
tableAssembies.Add(type);
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
return tableAssembies.ToArray();
|
||||
}
|
||||
List<Type> tableAssembies = new List<Type>();
|
||||
foreach (Type type in Assembly.GetAssembly(typeof(IEntity)).GetExportedTypes())
|
||||
foreach (Attribute attribute in type.GetCustomAttributes())
|
||||
if (attribute is TableAttribute tableAttribute)
|
||||
if (tableAttribute.DisableSyncStructure == false)
|
||||
tableAssembies.Add(type);
|
||||
|
||||
return tableAssembies.ToArray();
|
||||
}
|
||||
```
|
||||
调用
|
||||
@@ -166,18 +156,11 @@ public static Type[] GetTypesByNameSpace()
|
||||
"LinCms.Entities.Settings",
|
||||
"LinCms.Entities.Base",
|
||||
};
|
||||
|
||||
foreach (Type type in Assembly.GetAssembly(typeof(IEntity)).GetExportedTypes())
|
||||
{
|
||||
foreach (var fullname in entitiesFullName)
|
||||
{
|
||||
if (type.FullName.StartsWith(fullname) && type.IsClass)
|
||||
{
|
||||
tableAssembies.Add(type);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
return tableAssembies.ToArray();
|
||||
}
|
||||
```
|
||||
|
||||
Reference in New Issue
Block a user