Browse Source

ModelContext support inheritance

pull/12/MERGE
sunkaixuan 7 years ago
parent
commit
67358ab9ab
  1. 1
      Src/Asp.Net/SqlServerTest/Demos/6_ComplexModel.cs
  2. 2
      Src/Asp.Net/SqlSugar/Abstract/QueryableProvider/QueryableProvider.cs
  3. 11
      Src/Asp.Net/SqlSugar/Utilities/UtilMethods.cs

1
Src/Asp.Net/SqlServerTest/Demos/6_ComplexModel.cs

@ -12,6 +12,7 @@ namespace OrmTest.Demo
public static void Init()
{
var db = GetInstance();
db.Insertable(new CMStudent() { SchoolId = 1, Name = "xx1" }).ExecuteCommand();
var students = db.Queryable<CMStudent>().ToList();
if (students != null)
{

2
Src/Asp.Net/SqlSugar/Abstract/QueryableProvider/QueryableProvider.cs

@ -1180,7 +1180,7 @@ namespace SqlSugar
{
if (result.HasValue())
{
if (entityType.GetTypeInfo().BaseType.HasValue() && entityType.GetTypeInfo().BaseType == UtilConstants.ModelType)
if (UtilMethods.GetRootBaseType(entityType).HasValue() &&UtilMethods.GetRootBaseType(entityType) == UtilConstants.ModelType)
{
foreach (var item in result)
{

11
Src/Asp.Net/SqlSugar/Utilities/UtilMethods.cs

@ -17,6 +17,17 @@ namespace SqlSugar
return type==null ? oldType : type;
}
internal static Type GetRootBaseType(Type entityType)
{
var baseType = entityType.BaseType;
while (baseType != null && baseType.BaseType != UtilConstants.ObjType)
{
baseType = baseType.BaseType;
}
return baseType;
}
internal static Type GetUnderType(PropertyInfo propertyInfo, ref bool isNullable)
{
Type unType = Nullable.GetUnderlyingType(propertyInfo.PropertyType);

Loading…
Cancel
Save