Skip to content

Commit

Permalink
优化临时表功能
Browse files Browse the repository at this point in the history
  • Loading branch information
izanhzh committed Jul 17, 2024
1 parent ba04a6f commit 2e9944a
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 13 deletions.
2 changes: 1 addition & 1 deletion framework/Directory.Build.props
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<PropertyGroup>
<RootNamespace>Amos.Abp</RootNamespace>
<Authors>Amos</Authors>
<Version>2.0.1</Version>
<Version>2.0.2</Version>
<GeneratePackageOnBuild>true</GeneratePackageOnBuild>
<PackageLicenseExpression>MIT</PackageLicenseExpression>
<PackageReadmeFile>README.md</PackageReadmeFile>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
using Amos.Abp.TempTable.EntityFrameworkCore;
using Amos.Abp.TempTable;
using Amos.Abp.TempTable.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore;
using System;
using Volo.Abp.EntityFrameworkCore;
using Volo.Abp.EntityFrameworkCore.Modeling;

Expand All @@ -18,18 +20,33 @@ public static void AutoAddTempTableToModel<TDbContext>(this ModelBuilder modelBu
var tempTables = TempTableFinder.GetAutoAddTempTables(typeof(TDbContext));
foreach (var tempTable in tempTables)
{
var isExists = modelBuilder.Model.FindEntityType(tempTable) != null;
if (!isExists)
modelBuilder.AddTempTableToModel(tempTable);
}
}

/// <summary>
/// Note: Call it before base.OnModelCreating
/// </summary>
/// <typeparam name="TTempTable"></typeparam>
/// <param name="modelBuilder"></param>
public static void AddTempTableToModel<TTempTable>(this ModelBuilder modelBuilder) where TTempTable : ITempTable
{
modelBuilder.AddTempTableToModel(typeof(TTempTable));
}

internal static void AddTempTableToModel(this ModelBuilder modelBuilder, Type tempTableType)
{
var isExists = modelBuilder.Model.FindEntityType(tempTableType) != null;
if (!isExists)
{
modelBuilder.Model.AddEntityType(tempTableType);
modelBuilder.Entity(tempTableType, (b) =>
{
modelBuilder.Model.AddEntityType(tempTable);
modelBuilder.Entity(tempTable, (b) =>
{
//b.ToView(null);
b.ToTable("TempTable_" + tempTable.Name, (t) => t.ExcludeFromMigrations());
b.HasNoKey();
b.ConfigureByConvention();
});
}
//b.ToView(null);
b.ToTable("TempTable_" + tempTableType.Name, (t) => t.ExcludeFromMigrations());
b.HasNoKey();
b.ConfigureByConvention();
});
}
}
}
Expand Down

0 comments on commit 2e9944a

Please sign in to comment.