mirror of
https://gitee.com/dotnetchina/OpenAuth.Net.git
synced 2026-02-19 06:36:29 +08:00
转移.net core 3.1,为.NET 5做准备
This commit is contained in:
@@ -1,7 +1,7 @@
|
||||
<%@ Template Language="C#" TargetLanguage="C#" Debug="True" Encoding="UTF-8" %>
|
||||
|
||||
<%@ Assembly Src="Model.cs" %>
|
||||
<%@ Assembly Src="Extensions.cs" %>
|
||||
<%@ Assembly Src="../Internal/Model.cs" %>
|
||||
<%@ Assembly Src="../Internal/Extensions.cs" %>
|
||||
|
||||
<%@ Import Namespace="System.Collections.Generic" %>
|
||||
<%@ Import Namespace="System.Linq" %>
|
||||
@@ -10,87 +10,72 @@
|
||||
|
||||
<%@ Import Namespace="SchemaMapper" %>
|
||||
|
||||
<%@ Property Name="EntityContext" Type="SchemaMapper.EntityContext" %>
|
||||
<%@ Property Name="WholeDb"
|
||||
Type="System.Boolean"
|
||||
Category="1.Database"
|
||||
Default="true"
|
||||
Description="是否为整个数据库" %>
|
||||
|
||||
<%@ Property Name="SourceDatabase"
|
||||
Type="SchemaExplorer.DatabaseSchema"
|
||||
Category="1.Database"
|
||||
Description="The source database." %>
|
||||
|
||||
<%@ Property Name="SourceTables"
|
||||
Type="SchemaExplorer.TableSchemaCollection"
|
||||
Category="1.Database" Description="选择部分表" %>
|
||||
|
||||
<%@ Property Name="ContextNamespace" Type="System.String" %>
|
||||
<%@ Property Name="EntityNamespace" Type="System.String" %>
|
||||
<%@ Property Name="MappingNamespace" Type="System.String" %>
|
||||
<%@ Property Name="InterfaceMode" Type="Boolean" Default="False" Optional="True" %>
|
||||
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
// <autogenerated>
|
||||
// This code was generated by a CodeSmith Template.
|
||||
//
|
||||
// DO NOT MODIFY contents of this file. Changes to this
|
||||
// file will be lost if the code is regenerated.
|
||||
// </autogenerated>
|
||||
//------------------------------------------------------------------------------
|
||||
using System;
|
||||
using System.Data.Entity;
|
||||
using System.Collections.Generic;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using <%= EntityNamespace %>;
|
||||
using <%= MappingNamespace %>;
|
||||
|
||||
namespace <%= ContextNamespace %>
|
||||
{
|
||||
<% if (InterfaceMode) { %>
|
||||
public interface IDbContext : IDisposable
|
||||
{
|
||||
System.Data.Entity.Database Database { get; }
|
||||
System.Data.Entity.Infrastructure.DbChangeTracker ChangeTracker { get; }
|
||||
System.Data.Entity.Infrastructure.DbContextConfiguration Configuration { get; }
|
||||
|
||||
System.Data.Entity.Infrastructure.DbEntityEntry Entry(object entity);
|
||||
System.Data.Entity.Infrastructure.DbEntityEntry<TEntity> Entry<TEntity>(TEntity entity) where TEntity : class;
|
||||
|
||||
IEnumerable<System.Data.Entity.Validation.DbEntityValidationResult> GetValidationErrors();
|
||||
|
||||
System.Data.Entity.DbSet Set(Type entityType);
|
||||
System.Data.Entity.IDbSet<TEntity> Set<TEntity>() where TEntity : class;
|
||||
|
||||
int SaveChanges();
|
||||
}
|
||||
|
||||
public partial interface I<%= EntityContext.ClassName.ToSafeName() %> : IDbContext
|
||||
{
|
||||
<% foreach(var p in EntityContext.Entities) { %>
|
||||
System.Data.Entity.IDbSet<<%= EntityNamespace %>.<%= p.ClassName.ToSafeName() %>> <%= p.ContextName.ToSafeName() %> { get; set; }
|
||||
<% } // foreach %>
|
||||
}
|
||||
|
||||
<% } // if interface %>
|
||||
public partial class <%= EntityContext.ClassName.ToSafeName() %>: DbContext<%= InterfaceMode ? ", I" + EntityContext.ClassName.ToSafeName() : string.Empty %>
|
||||
{
|
||||
static <%= EntityContext.ClassName.ToSafeName() %>()
|
||||
{
|
||||
Database.SetInitializer< <%= EntityContext.ClassName.ToSafeName() %>>(null);
|
||||
<%
|
||||
string dbContextName;
|
||||
if(WholeDb){
|
||||
dbContextName = SourceDatabase.Name.ToSafeName();
|
||||
}
|
||||
public <%= EntityContext.ClassName.ToSafeName() %>()
|
||||
:base("Name=<%= EntityContext.ClassName.ToSafeName() %>")
|
||||
{ }
|
||||
|
||||
public <%= EntityContext.ClassName.ToSafeName() %>(string nameOrConnectionString)
|
||||
: base(nameOrConnectionString)
|
||||
{ }
|
||||
|
||||
<% foreach(var p in EntityContext.Entities) { %>
|
||||
public System.Data.Entity.<%= InterfaceMode ? "I" : "" %>DbSet<<%= p.ClassName.ToSafeName() %>> <%= p.ContextName.ToSafeName() %> { get; set; }
|
||||
<% } // foreach %>
|
||||
|
||||
protected override void OnModelCreating(DbModelBuilder modelBuilder)
|
||||
else{
|
||||
dbContextName = SourceTables.First().Database.Name.ToSafeName();
|
||||
}
|
||||
dbContextName = StringUtil.ToPascalCase(dbContextName);
|
||||
Response.WriteLine(" public partial class "+ dbContextName +"Context: DbContext");
|
||||
|
||||
%>
|
||||
{
|
||||
|
||||
protected override void OnModelCreating(ModelBuilder modelBuilder)
|
||||
{
|
||||
<% foreach(var p in EntityContext.Entities) { %>
|
||||
modelBuilder.Configurations.Add(new <%= p.MappingName.ToSafeName() %>());
|
||||
<% } // foreach %>
|
||||
//当主键为联合主键时,需要把这里的内容拷贝到对应的位置
|
||||
<%
|
||||
TableSchemaCollection tables;
|
||||
if(WholeDb){
|
||||
tables = SourceDatabase.Tables;
|
||||
}
|
||||
else{
|
||||
tables = SourceTables;
|
||||
}
|
||||
|
||||
// InitializeMapping(modelBuilder);
|
||||
foreach(TableSchema table in tables)
|
||||
{
|
||||
if(table.PrimaryKeys.Count <=1) continue;
|
||||
var keys = string.Join(",", table.Columns.Where(u=>u.IsPrimaryKeyMember==true)
|
||||
.Select(u =>"c."+u.Name));
|
||||
Response.WriteLine(" modelBuilder.Entity<"+table.Name+">()");
|
||||
Response.WriteLine(" .HasKey(c => new { "+keys+" });");
|
||||
}
|
||||
%>
|
||||
}
|
||||
<% if (InterfaceMode) { %>
|
||||
|
||||
System.Data.Entity.IDbSet<TEntity> IDbContext.Set<TEntity>()
|
||||
<%
|
||||
foreach(TableSchema table in tables)
|
||||
{
|
||||
return base.Set<TEntity>();
|
||||
Response.WriteLine(" public virtual DbSet<"+table.Name+"> "+StringUtil.ToPascalCase(StringUtil.ToPlural(table.Name))+" { get; set; }");
|
||||
}
|
||||
<% } // if interface %>
|
||||
%>
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user