我正在使用EntityFramework Core
使用Oracle.EntityFrameworkCore(2.18.0-beta3)
进行配置和操作数据,但是收到了"OracleException: ORA-00942: table or view does not exist"
。
Oracle.EntityFrameworkCore(2.18.0-beta3)
正在工作,因为我可以使用“带有实体框架的带有视图的MVC控制器”来搭建一个新的Controller,该控制器将创建和编辑Oracle表(已创建Clients和IdentityResources Controllers)。
Startup.cs ConfigureServices包含以下配置:
var builder = services.AddIdentityServer(options =>
{
options.Events.RaiseErrorEvents = true;
options.Events.RaiseInformationEvents = true;
options.Events.RaiseFailureEvents = true;
options.Events.RaiseSuccessEvents = true;
})
// this adds the config data from DB (clients, resources)
.AddConfigurationStore(options =>
{
options.ConfigureDbContext = b =>
b.UseOracle(connectionString);
})
.AddOperationalStore(options =>
{
options.ConfigureDbContext = b =>
b.UseOracle(connectionString);
options.EnableTokenCleanup = true;
});
将显示“欢迎使用IdentityServer4(版本2.4.0.0)”页面,并将其路由到控制器选项,但是“发现文档”(http://localhost:5000/.well-known/openid-configuration)返回
"OracleException: ORA-00942: table or view does not exist"
。
答案 0 :(得分:0)
使其与Oracle.EntityFrameworkCore(2.19.0-beta4)一起使用。一路上我学到了几件事:
1)Oracle的许多实例都遵循SQL-92标准,该标准将对象(包括表名和列名)限制为30个字符。默认的IdentityServer4
“客户”表中的几个列名超过30个字符。 EF迁移已修改,以适应列名字符限制。
b.Property<bool>("AlwaysIncludeUserClaimsInIdToken")
.HasColumnName("AlwaysIncludeUserClaimsInIdTok");
2)Oracle处理增量主键的方式与SQLServer不同。 EF迁移Oracle:ValueGenerationStrategy
属性用于所有主键。
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasAnnotation("Oracle:ValueGenerationStrategy", OracleValueGenerationStrategy.IdentityColumn);
3)如果Oracle表名全部以大写形式创建,则它们不区分大小写。如果它们是大小写混合的,则区分大小写。我能够使用默认的IdentityServer4
表名与IdentityServer4
一起使用Oracle。但是,我选择通过将EF属性更改为大写来将表名更改为全部大写:
migrationBuilder.CreateTable(name: "IS4_CLIENT",
b.ToTable("IS4_CLIENT"),
principalTable: "IS4_CLIENT",
IdentityServer4
配置存储属性需要更改,以匹配更改后的大写表名称。以下是用于配置IdentityServer4
AddConfigurationStore
和AddOperationalStore
的扩展类。
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using System.Reflection;
using Microsoft.Extensions.DependencyInjection;
using Oracle.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore;
using IdentityServer4.EntityFramework.Entities;
namespace is4ef.Extensions
{
public static class Is4BuilderExtensions
{
public static string IdentityResource { get; private set; }
public static IIdentityServerBuilder AddIs4ConfigurationStore(
this IIdentityServerBuilder builder, string connectionString)
{
string assemblyNamespace = typeof(Is4BuilderExtensions)
.GetTypeInfo()
.Assembly
.GetName()
.Name;
builder
.AddConfigurationStore(options => {
options.ConfigureDbContext = b =>
b.UseOracle(connectionString, optionsBuilder =>
optionsBuilder.MigrationsAssembly(assemblyNamespace)
.UseOracleSQLCompatibility("12"));
options.DefaultSchema = "X13663";
options.ApiClaim.Name = "IS4_AIPCLAIM";
options.ApiResourceProperty.Name = "IS4_APIPROPERTY";
options.ApiResource.Name = "IS4_APIRESOURCE";
options.ApiScopeClaim.Name = "IS4_APISCOPECLAIM";
options.ApiScope.Name = "IS4_APISCOPE";
options.ApiSecret.Name = "IS4_APISECRET";
options.ClientClaim.Name = "IS4_CLIENTCLAIM";
options.ClientCorsOrigin.Name = "IS4_CLIENTCORSORIGIN";
options.ClientGrantType.Name = "IS4_CLIENTGRANTTYPE";
options.ClientIdPRestriction.Name = "IS4_CLIENTIDPRESTRICTION";
options.ClientPostLogoutRedirectUri.Name = "IS4_CLIENTPOSTLOGOUTREDIRECTURI";
options.ClientProperty.Name = "IS4_CLIENTPROPERTY";
options.ClientRedirectUri.Name = "IS4_CLIENTREDIRECTURI";
options.Client.Name = "IS4_CLIENT";
options.ClientScopes.Name = "IS4_CLIENTSCOPE";
options.ClientSecret.Name = "IS4_CLIENTSECRET";
options.IdentityClaim.Name = "IS4_IDENTITYCLAIM";
options.IdentityResourceProperty.Name = "IS4_IDENTITYPROPERTY";
options.IdentityResource.Name = "IS4_IDENTITYRESOURCE";
})
.AddOperationalStore(options => {
options.ConfigureDbContext = b =>
b.UseOracle(connectionString, optionsBuilder =>
optionsBuilder.MigrationsAssembly(assemblyNamespace)
.UseOracleSQLCompatibility("12"));
options.DefaultSchema = "X13663";
options.DeviceFlowCodes.Name = "IS4_DEVICECODE";
options.PersistedGrants.Name = "IS4_PERSISTEDGRANT";
});
return builder;
}
}
}