1

I'm new to Entity Framework, and currently developing an MVC 5 application with Code-First Entity Framework 6.1.2.

I need to write custom reports. Instead of writing complex linq, I can write a couple quick Stored Proc's and write the results to CSV. Can I call these procs with EF? or would I just be better off using ADO.NET?

I know I can do:

var data = db.Database.SqlQuery<ReportDetailed>("sp_rpt_report @reportType @endDate, @startDate", parameters).ToList<ReportDetailed>();

But I would need to build a rather large model for each report result, and that seems like a lot of work for little reward and wrong.

1
  • Linq is very similar to SQL. Perhaps you should learn Linq and EF a little better, and then make up your mind? Commented Jul 31, 2015 at 14:17

1 Answer 1

0

I think Robert Harvey's comment is very good advice. In the long-run, I think you'll wish you did it in Linq.

Here's why:

  1. Changes in Entity Framework for your data objects will be easier to make changes to the report data sets. The stored procedures will probably just fail. You'll need to maintain them separately. There will be no shared logic that can be reused.
  2. You'll learn Linq much better.

I do think you can take a few steps to accomplish this. It sounds like you're better at this in sql and you may have some pressure to get this done. So go ahead and create a stored procedure that works. You'll understand the requirements better. Then you can get to work on refactoring it in linq. You'll have a result set from the stored procedure that you can use to test/compare your Linq results. You'll feel more comfortable knowing you've been able to accomplish the same thing in the new language.

This way you can get your app into production in parallel with becoming a better Linq programmer. The next programmer that has to maintain this app will appreciate it. And don't forget, that new programmer could be you in a year or so.

1
  • Thats for the advance, I probably should have stated that I'm not new to linq lmaba and linq sql. , but new to EF with MVC (lived in webforms / nettiers/dapper orms for far to long). Just that I would have a pretty complex linq statement with joins and filters for reporting purposes. I feel the ability to improve performance issues would be easier in the sql end then linq. What I've been reading its EF6 as long as you do linq to sql it writes decently optimized queries. Linq seems the way to go and deal with any performance issues later.
    – chatters
    Commented Jul 31, 2015 at 18:26

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.