I am working on an ASP.NET Web Forms
project. Due to the specifics of the project most of the data is in XML
files, and when I return data from some view I have only a string
value of the Entity type that I'm working with. Or to make it more clear, I return json
where I have something like {entity : "Clients"}
and that's the only way for me to know that I'm working with Clients
at the moment.
So we still try to hang on to Entity Framework 5
so in the XML
files we store our DB queries, but the problem is that when I want to execute :
using(var db = new MyContext())
{
var allRecords = db.Database.SqlQuery<???>("SELECT * FROM Clients");
I don't have the type as real type to give to the SqlQuery
method. So the options that I think I can consider here are :
- Using classes to match the data - the most common answer when it comes to this problem but in my case the extensive use of
XML
files would be pointless. - Using some sort of reflection to cast my string value to the actual Entity type since I have them in
POCOs
(I'm usingDataBase first
approach). I saw some pointers on how eventually this could be done here but to be honest it's pretty complicated for me and I'm not even sure if this will work in that particular scenario, but if you think it's a good way to go please mention it. - I was wondering if I can use
dynamic
somehow like soSqlQuery<dynamic>
- it's returning correctly all the records from the database but I can't extract any data from that. I guess with dynamic I still have to cast the result at some point. Not sure, maybe someone knows a way? - And last. We really want to use
Entity Framework
but this is just the starting phase of the project trying things out, seeing how things work together and I'm starting to think that maybeEntity Framework
is just not the right tool in this situation. I got this brief answer here and it really made me think about if I should put effort into twisting something when there's just a better approach doing it.