Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Migrating customized Linq-2-SQL to Entity Framework

I have a data layer built on Linq-2-SQL in .net 3.5. We're looking at migrating to .Net 4. soonish. When we started the original development I was interested in using EF for the data layer, but found it wasn't really an option in .Net 3.5. Now that we're upgrading, I'm thinking it over again.

I realise that L2S is still supported in .Net4, however I would be keen to switch to the more active area of development for the future proofing of a system that's likely to be core to the business for a fair while. (My understanding is based on statements such as "We said we would improve the core of it (L2S) and add customer requests where it makes sense but that Entity Framework would be the primary focus." from Damien Guard in the comments to this post.

What complicates it a bit is that we have made a few mods to our L2S implementation:

  • We've customized the .tt generating file a fair bit, and L2ST4 slightly.
  • We're using stored procs for all CRUD operations (which we generate automatically), as this allows us to switch on/off a granular audit trail on specific tables as we need.

Most of the rest of what we use I know will be ok because I've done it myself in EF4 (in fact a lot of it started life on an EF4 database), but I wanted to know if the above customizations are going to be problems.

So:

  • Can we still have a customized .tt type generating system (or something similar)?
  • Can we still use our own defined sprocs for CRUD?

NB: If we used EF I would probably use the Database First version.

like image 209
Jon Egerton Avatar asked Nov 04 '22 17:11

Jon Egerton


1 Answers

Can we still have a customized .tt type generating system (or something similar)?

Yes. In VS 2012 you can use a DbContext generator which uses a T4 template to generate your DbContext and persistence-ignorant classes.

Once you add it and point it to your edmx file, you can modify the templates all you want to customize the output.

If you're using VS.NET 2010, then you can install the EF 5.x DbContext Generator for C# extension from the Visual Studio Gallery to install the template generator and have it added to the "Add Item" menu in VS.NET.

Can we still use our own defined sprocs for CRUD?

Yes, it's simply a matter of mapping the conceptual model (what you work with in the edmx files) to the physical model (the representation of the database). In the mapping, you'd specify the stored procedure instead of having it done dynamically.

Julie Lerman goes into detail on how to map your CRUD operations to stored procedures in the section of the MSDN documentation titled "Stored Procedures in the Entity Framework".

like image 83
casperOne Avatar answered Nov 08 '22 06:11

casperOne