UnitOfWork icon indicating copy to clipboard operation
UnitOfWork copied to clipboard

some question when use this in my project, help!

Open backwzw opened this issue 7 years ago • 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?

backwzw avatar Oct 31 '18 10:10 backwzw

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();

rigofunc avatar Nov 04 '18 10:11 rigofunc

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.

backwzw avatar Nov 05 '18 03:11 backwzw

Yes, EF have this tool.

rigofunc avatar Nov 12 '18 03:11 rigofunc

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

backwzw avatar Nov 12 '18 03:11 backwzw

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.

backwzw avatar Dec 24 '18 07:12 backwzw

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

xye1989 avatar Jun 21 '21 13:06 xye1989