We are looking to migrate our database to SQL Azure, but as the pricing model for Azure is different than that for SQL 2k8R2 (obviously) we need to re-think the structure of our database. The structure right now is one database per customer, but with Azure we need to pay per database even though we might just use a fraction of the capacity (in the range of 10MB). This makes it problematic for us. The easiest solution would be to prefix each table in the model with the customers unique identifier. Is there anyway of changing the mapping at runtime, or is this scenario not fit for Azure?
I asked a similar question a couple of weeks ago, but not quite the same: Change table name at runtime using Entity Framework 4
EDIT: I tried federation in SQL Azure, but it d开发者_StackOverflow社区oes not seem to be live yet. The solution I'v come up with is to have multiple customers in one DB, with support for partions. Our repository is now exposing IQueryables with a Where-func already included to seperate the entities for a specific customer:
public IQueryable<TestEntity>
{
get
{
return _ctx.Set<TestEntity>().Where(entity => entity.CustomerId == _customerId);
}
}
You could consider using schema.
For each customer, you create : - a login on the server - a user mapped to this login - a schema, owned by this user - and you define the schema as the default one for the user
If you do not use the [schema].[objectname] notation but only the [objectname] one, then the default schema will be used.
Surely not the perfect solution, but it should work.
精彩评论