I am writing mock of DbSets and ended up writing series of code like this.
int rowCount = 0;
var maxOrderId = EntityContainer.Set<Order>().Max(a => a.Id);
var newOrders = EntityContainer.Set<Order>().Where(a =>a.Id == 0);
foreach (var order in newOrders)
{
order.Id = ++maxOrderId;
rowCount++;
}
var maxServiceId = EntityContainer.Set<Service>().Max(a => a.Id);
var newServices = EntityContainer.Set<Service>().Where(a => a.Id == 0);
foreach (var service in newServices)
{
service.Id = ++maxServiceId;
rowCount++;
}
There are more entities though in this list. Is there a way I can extract these to a generic method? Something like:
int GenerateID<Order>();
I tried using dynamic
, but that compiler complains that dynamics are not allowed in lambda expressions.