How to set the AliasName in different Mode in code

In development, I had connect to local sqlserver , the tablename is EISQueue, in the proudction server, sqlserver tablename is radfs.EISQueue,
there are had different schema, so how to set the AliasName in different Mode in code?

    [Alias("radfs.EISQueue")]
    public class EISQueue_FS : EISQueue
    {

    }

As C# Attributes are compile-time metadata statically embedded in compiled .dll’s you would need to use conditional compilation, e.g. in this case you can specify to use the radfs schema in Release builds with:

#if !DEBUG
[Schema("radfs")]
#endif
[Alias("EISQueue")]
public class EISQueue_FS : EISQueue {}

Alternatively you can use your own custom build symbol used when building for production.

However ServiceStack’s Reflection Utils also lets you add attributes to ServiceStack Models which is more fragile as it need to be added before the models are accessed by the library using them (OrmLite) e.g. before registering your AppHost or in its constructor:

if (!env.IsDevelopment())
{
    typeof(EISQueue_FS)
        .AddAttributes(new SchemaAttribute("radfs"));
}
1 Like