I am using a Multitenant Application for various companies . I am yet to get success with this . But what my scenario is I have a single sql server database with tablesets with different companies (tenants).
So what I want to do is add a convention for table which would access the table with its schema prefix in the table as per multitenant application concept . I am not using database per tenant but using schema per tenant . Database file is a single file .
What I want to do is my tables are like this Sachin Sales & Service Pvt Ltd$Web User Setup Header. so I want when the table queries would be generated they should add prefix Sachin Sales & Service Pvt Ltd on fly before querying . The prefix may change on requirement . Its not static . So I thought of overriding IClassConvention which by default looks like this
public class TableNameConvention : IClassConvention
{
public void Apply(IClassInstance instance)
{
instance.Table( instance.EntityType.Name);
}
}
Is there anyway I can pass another parameter like string schemaname like this to generate the desired tablename with schema prefix ? My idea is to do something like this :
public class TableNameConvention : IClassConvention
{
public void Apply(IClassInstance instance, string schemaname )
{
instance.Table(schemaname + instance.EntityType.Name);
}
}
If so my questions are here like this . If i am able to achieve the point mentioned above will it solve my schema per tenant problem ?
And second even if the above doesnt give any errors while compiling (technically shouldnt) how am I supposed to pass schemaname into that override ? I mean how should I call since This is just a convention and I cannot manipulate it on fly (which I actually want to do)
you can set the schema use for all tables when configuring nhibernate, e.g.