是否可以为ServiceStack的Auth功能指定架构?

时间:2015-02-05 14:25:34

标签: servicestack ormlite-servicestack

ServiceStack.Ormlite允许我们使用Schema属性来装饰数据库表类,以表示它们属于数据库中的哪个模式。

这对所有表格都很有用,除了看起来是由Auth功能创建的表格。是否可以指定Auth表应属于哪个模式?我宁愿不使用自定义类纯粹用Schema属性来装饰。

如果没有,我想我应该在某处请求更改?

编辑1 - 遵循mythz的建议

我在初始化构造函数中添加了该属性..

public class AuthenticationInitialisation : AppInitialisation
{
    private readonly IAppSettings _appSettings;

    public AuthenticationInitialisation(IAppSettings appSettings)
    {
        _appSettings = appSettings;
        typeof(UserAuth).AddAttributes(new SchemaAttribute("Admin"));
        typeof(UserAuthDetails).AddAttributes(new SchemaAttribute("Admin"));
        typeof(UserAuthRole).AddAttributes(new SchemaAttribute("Admin"));
    }...

我已从SQL用户中删除了默认架构,并在DropAndRecreateTables()上获得了异常......

var authRepo = (OrmLiteAuthRepository)appHost.TryResolve<IUserAuthRepository>();
if (_appSettings.Get("RecreateAuthTables", false))
    authRepo.DropAndReCreateTables(); //Drop and re-create all Auth and registration tables
else...

异常读取

  

不能删除“UserAuth”表,因为它不存在或您没有权限。

由SQL事件探查器验证,显示以下内容已传递到SQL Server

DROP TABLE "UserAuth"

编辑2 - 更改为MyGet预发布ServiceStack版本后

我现在收到以下错误..

  

ServiceStack.dll中出现'System.MissingMethodException'类型的异常,但未在用户代码中处理

     

其他信息:未找到方法:'Void ServiceStack.MetadataTypesConfig..ctor(System.String,Boolean,Boolean,Boolean,Boolean,Boolean,Boolean,System.String,Boolean,Boolean,Boolean,Boolean,Boolean,System .Nullable`1)”

Stack Trace ..

  

在ServiceStack.NativeTypesFeature..ctor()      at ServiceStack.ServiceStackHost..ctor(String serviceName,Assembly [] assembliesWithServices)      at ServiceStack.Host.HttpListener.HttpListenerBase..ctor(String serviceName,Assembly [] assembliesWithServices)      at ServiceStack.AppHostHttpListenerBase..ctor(String serviceName,Assembly [] assembliesWithServices)      在MyProduct.AppHost..ctor(IEnumerable`1 initialisations)中的d:\ dev \ App_Code \ AppHost.cs:第14行      在MyProduct.Global.Application_Start(Object sender,EventArgs e)的d:\ dev \ Global.asax.cs:第29行

在我的AppHost构造函数上..

public AppHost(IEnumerable<IAppInitialisation> initialisations) : base("RESTful Web API", typeof(SystemsService).Assembly)
{
    if (initialisations == null)
    {
        _initialisations = new IAppInitialisation[0];
    }
    else
    {
        _initialisations = initialisations.ToArray();
    }
}

如果使用模式进入下一个ServiceStack版本,那么我将暂时等待并设置SQL用户的默认模式。

1 个答案:

答案 0 :(得分:0)

尝试动态地将schema属性添加到UserAuth表,即:

typeof(UserAuth)
    .AddAttributes(new SchemaAttribute("MySchema"));

typeof(UserAuthDetails)
    .AddAttributes(new SchemaAttribute("MySchema"));
相关问题