arch / UnitOfWork

A plugin for Microsoft.EntityFrameworkCore to support repository, unit of work patterns, multiple database with distributed transaction supported, and MySQL multiple databases/tables sharding supported.
MIT License
1.34k stars 342 forks source link

some question when use this in my project, help! #87

Open backwzw opened 6 years ago

backwzw commented 6 years ago

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?
rigofunc commented 6 years ago

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();
backwzw commented 6 years ago

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.

rigofunc commented 6 years ago

Yes, EF have this tool.

backwzw commented 6 years ago

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

backwzw commented 5 years ago

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.

xye1989 commented 3 years ago

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