Click here to Skip to main content
15,888,320 members
Home / Discussions / C#
   

C#

 
QuestionEF dynamic CRUD Pin
jackie.398117-Feb-16 3:38
jackie.398117-Feb-16 3:38 
AnswerRe: EF dynamic CRUD Pin
Dave Kreskowiak17-Feb-16 4:33
mveDave Kreskowiak17-Feb-16 4:33 
GeneralRe: EF dynamic CRUD Pin
jackie.398117-Feb-16 4:49
jackie.398117-Feb-16 4:49 
GeneralRe: EF dynamic CRUD Pin
Dave Kreskowiak17-Feb-16 5:07
mveDave Kreskowiak17-Feb-16 5:07 
GeneralRe: EF dynamic CRUD Pin
jackie.398117-Feb-16 5:22
jackie.398117-Feb-16 5:22 
GeneralRe: EF dynamic CRUD Pin
Dave Kreskowiak17-Feb-16 7:03
mveDave Kreskowiak17-Feb-16 7:03 
GeneralRe: EF dynamic CRUD Pin
jackie.398117-Feb-16 9:03
jackie.398117-Feb-16 9:03 
AnswerRe: EF dynamic CRUD Pin
Sascha Lefèvre17-Feb-16 5:36
professionalSascha Lefèvre17-Feb-16 5:36 
I'm no EF-expert but I have some experience with dynamically building query expressions. As Dave already said there's no inbuilt solution in EF for this, I'm pretty sure this would be your only alternative to constructing SQL statements:

For deletion: Build query expressions (the where-clause) dynamically using System.Linq.Expressions. Execute the query and Remove(..) the returned entities. *

For updating: Build query expressions (the where-clause) dynamically using System.Linq.Expressions. Execute the query and update the entities via Reflection. *

For adding: Create the entities via Reflection, set their properties via Reflection and Add(..) them.

For all this you would have to discover the DbSet<EntityName> -properties and Entity-types in your DbContext-class via Reflection. If the names of the properties don't exactly match those in your XML you would need to manually build a mapping dictionary.

99% sure this would work but it's a pretty big task and since (as I already saw from your last reply to Dave) you're not experienced with Reflection, I assume you would be done faster with constructing SQL statements. If you want to give this a try anyway, feel free to ask for more advice.

* Edit:
Instead of dynamically builing the query expressions you also could just "dumbly" loop over all entities in a DbSet and "scan" for those which should be deleted/updated by reading their properties with Reflection.
If the brain were so simple we could understand it, we would be so simple we couldn't. — Lyall Watson


modified 17-Feb-16 12:05pm.

GeneralRe: EF dynamic CRUD Pin
jackie.398117-Feb-16 6:51
jackie.398117-Feb-16 6:51 
AnswerRe: EF dynamic CRUD Pin
Gerry Schmitz17-Feb-16 17:51
mveGerry Schmitz17-Feb-16 17:51 
QuestionBoss just gave me ReSharper Ultimate Pin
Ian Klek16-Feb-16 22:28
Ian Klek16-Feb-16 22:28 
AnswerRe: Boss just gave me ReSharper Ultimate Pin
OriginalGriff16-Feb-16 23:17
mveOriginalGriff16-Feb-16 23:17 
AnswerRe: Boss just gave me ReSharper Ultimate Pin
Pete O'Hanlon16-Feb-16 23:31
mvePete O'Hanlon16-Feb-16 23:31 
GeneralRe: Boss just gave me ReSharper Ultimate Pin
John Torjo18-Feb-16 6:40
professionalJohn Torjo18-Feb-16 6:40 
JokeRe: Boss just gave me ReSharper Ultimate Pin
Sascha Lefèvre16-Feb-16 23:31
professionalSascha Lefèvre16-Feb-16 23:31 
GeneralRe: Boss just gave me ReSharper Ultimate Pin
Foothill18-Feb-16 5:33
professionalFoothill18-Feb-16 5:33 
AnswerRe: Boss just gave me ReSharper Ultimate Pin
Kornfeld Eliyahu Peter17-Feb-16 1:01
professionalKornfeld Eliyahu Peter17-Feb-16 1:01 
AnswerRe: Boss just gave me ReSharper Ultimate Pin
BillWoodruff17-Feb-16 3:10
professionalBillWoodruff17-Feb-16 3:10 
AnswerRe: Boss just gave me ReSharper Ultimate Pin
Ravi Bhavnani17-Feb-16 11:11
professionalRavi Bhavnani17-Feb-16 11:11 
GeneralRe: Boss just gave me ReSharper Ultimate Pin
Pete O'Hanlon18-Feb-16 5:39
mvePete O'Hanlon18-Feb-16 5:39 
QuestionNamed pipes: C# server, C++ client Pin
Crazy Joe Devola16-Feb-16 8:57
Crazy Joe Devola16-Feb-16 8:57 
AnswerRe: Named pipes: C# server, C++ client Pin
Richard Andrew x6416-Feb-16 9:31
professionalRichard Andrew x6416-Feb-16 9:31 
GeneralRe: Named pipes: C# server, C++ client Pin
Crazy Joe Devola16-Feb-16 9:35
Crazy Joe Devola16-Feb-16 9:35 
GeneralRe: Named pipes: C# server, C++ client Pin
Richard Andrew x6416-Feb-16 9:46
professionalRichard Andrew x6416-Feb-16 9:46 
GeneralRe: Named pipes: C# server, C++ client Pin
Crazy Joe Devola16-Feb-16 10:03
Crazy Joe Devola16-Feb-16 10:03 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.