arch/UnitOfWork

some question when use this in my project, help!

backwzw opened this issue · 6 comments

recently, in my project, a table in database should splited as many tables, each table has the same data struct, and they are splited by a column data. Now, i have some question as follows:

  1. i need to generator table dynamic by the column data, how can i do?
  2. when the server starting, how to load splited table data in one repository?

This is a complex question, as what have I known, there have not one perfect solution for any requirement. Assume your table named as tableName_xxx, and the xxx is determined by a column data, your can dynamic change table name by ChangeTable

var repository = unitOfWork.GetRepository<TEntity>();
var xxx = GetxxxByColumnValue(columnValue);
repository.ChangeTable(@"tableName_{xxx}");
repository.Insert(entityInstance);
unitOfWork.SaveChanges();

Tanks for you answer, what you said is what i do now, but the table should be built in database manualtly, i want to konw whether has a way to generator table automatically.

Yes, EF have this tool.

I know, but EFC2.1 can't. That's sad. At all, Thanks for your help!

recently, when i change table in a loop, it cant change table sucesssfully, and query in default table likes table_name_0. And the once i reset database when problem comes, it will be success in querying.
in my project, not only use your framework, Pomelo.EntityFrameworkCore.MySql also is used. Because the old project's database not spliting table, and now i want to split some table but not all table.

when i execute changetable, it is throw " Object reference not set to an instance of an object. " why?