0

I have software that creates sql tables during runtime. So none of it is known at design time. The software does not use entity framework and has it's own ways of reading the data from those tables (old school ADO).

Now I have new, separate piece of software (an API written from scratch) that uses EF, and it needs to read the data in these tables. On the fly I can create a SQL statement that will read these tables. It looks something like...

select ID0 , [Notes:5216] as [Notes5216], [Date:11512] as [Date11512] from [aCFProject_POS Install_1573] where ID0 = 44778

How do I take a sql query like the above and return the data in EF? The table name or column names aren't known until run time.

3
  • 1
    EF is absolutely not the right tool for dynamic querying at runtime. Use Dapper, piece of cake. Commented May 1, 2020 at 22:09
  • Not an option at this point. Have to use EF. Commented May 1, 2020 at 22:17
  • 2
    Can't be. You're a software professional, entitled to choose the tool for the job. Would a surgeon operate without the right tools? Believe me, EF is a disaster in this area. Even ADO.Net is a much better fit. Dapper is a very well received little gem, widely used, even part of Stack Overflow's software stack. Commented May 1, 2020 at 22:31

1 Answer 1

1

If you absolutely need to use EF, then basically you need to always have the mapping created and the classes written. Luckily, this can be done based on the database. Luckily you can resolve this via CLI as well. And since this can be resolved via CLI, you can also programmatically run it. So, I would ensure that program1 is able to run the CLI commands to refresh the EF of program2. If this milestone is complete, then you would just need to map the events/functionalities where this should be triggered. Of course, when the EF is refreshed, it's advisable to schedule a rebuild and a restart as well.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.