Reputation: 1007
I just want to ask if this is possible in Linq
I have 3 identical tables:
TableA TableB TableC
Name Name Name
Age Age Age
before inserting the values, i need to choose what table to insert into. The condition should be like this:
var TableABC = new Table;
if(str == 'a')
{
TableABC = TableA;
}
else if (str == 'b')
{
TableABC = TableB;
}
else
{
TableABC = TableC;
}
var Save = new TableABC
{
Name = 'John Smith',
Age = 30
}
Context.Table.AddObject(TableABC);
Context.SaveChanges();
Upvotes: 1
Views: 97
Reputation: 1007
I found a solution.. Instead of using var i used dynamic..
var TableABC = new Table;
to
dynamic TableABC;
Upvotes: 1
Reputation: 2910
It would more helpful to create entity objects and use the objects like below
switch(str)
case 'a':
context.EntityA.Add(obj);
context.SaveChanges();
break;
etc...
Now about how to create entity objects (which is very easy as they are plain classes) and use EF and create context you can ready this tutorial:
Upvotes: 0