Why use the Entity Framework with SQL Azure? - SQL Azure Team Blog - Site Home - MSDN Blogs

Why use the Entity Framework with SQL Azure?

Why use the Entity Framework with SQL Azure?

  • Comments 15

This week I’ll be spending some time diving into using Entity Framework with SQL Azure.

The Entity Framework provides the glue between your object oriented code and the SQL Azure relational database in a framework that is fully compatible with your skills and development tools. Integrated into Visual Studio, and part of ADO.NET, the entity framework provides object relational map capabilities that help an application developer focus on the needs of the application as opposed to the complexities of bridging disparate data representations.

If you’re new to Entity Framework, MSDN has some great resources as well as walkthrough tutorials that quickly get you started. Go here to learn more.

I like to use the Entity Framework with SQL Azure because:

  • I can write code against the Entity Framework and the system will automatically produce objects for me as well as track changes on those objects and simplify the process of updating SQL Azure.
  • Model first design (which I am blogging about in a future post), gives me an easily way to design SQL Azure database schemes. A good walkthrough of this technique is here.
  • It is integrated deeply with Visual Studio so there is no flipping between applications to design the database, generated my objects, write my code and execute Transact-SQL – it’s all done inside Visual Studio.
  • The Entity Framework replaces a large chunk of data-access code I used to have to write and maintain myself – pure laziness here.
  • The mapping between my objects and my database is specified declaratively instead of in code, if I need to change the database schema, I can minimize the impact on the code that I have to modify in my applications -- so the system provides a level of abstraction which helps isolate the app from the database. Plus, I don’t have to touch the code to change the mapping, properties of the entities, and the Entity Framework designer do that for me.
  • The queries and other operations I write into code are specified in a syntax that is not specific to any particular database, I can easily move from SQL Express, to SQL Azure, to an on-premise SQL Server. With the Entity Framework, the queries are written in LINQ or Entity SQL and then translated at runtime by the providers to the particular back-end query syntax for that database.

Do you have questions, concerns, comments? Post them below and we will try to address them.

  • How about SQL Connection retries? Does EF does it or you have to implement it?

  • Hi teja - at this point EF doesn't retry the connection. However, the engineering team is aware of the issue and will be publishing guidance on this in the next few weeks and we'll make sure to make it available here.  Additionally, they have this as a priority item in planning for future updates.

    Thanks for your comments!

  • When implementing sharding/partitioning in the application layer, what is the recommended way of changing the connection string among the partitions when using EF?

  • I used the same concept some time back while architecting one of the enterprise application when azure itself was in beta. Here is the typical architecture diagram for that


    The most important thing you need to keep in mind is the designing of Entity Model, and this is different from traditional application because here you pay for every call to DB in terms of processing and transaction cost also. Try to minimize as much you can

  • >Hi teja - at this point EF doesn't retry the connection. However, the engineering team is

    >aware of the issue and will be publishing guidance on this in the next few weeks and we'll

    >make sure to make it available here

    It's now 10/19/2010, almost two months after your comment above.  I looked around the blog but could not find any guidance on this, except for the white paper on SQL Azure data connections, which is very general.  Did I miss something?

    We are using Entity Framework (Model first) on SQL Azure and we see this problem daily.  I could go over each context/sql call we make and wrap it in a try...catch, but ideally I'd like the Entity Framework to do it.  

    I blogged about this problem and how I solved it for another ORM (.netTiers) here: blog.ehuna.org/.../how_to_stop_getting_exceptions.html - I'm looking for something similar in EF (can I inherit the context and do the retry in that class?)

  • Hhhmmm, I wouldn't expect a response.  MS knows about this issue and knows EF4 is unusable with SQL Azure right now but won't comment further... it's a shame.  There's really no reason to not answer... and in the meantime, all of us who have invested in EF and SQL Azure and left out in the cold...

  • Mike, Ehuna: Microsoft is completely behind SQL Azure and Entity Framework and this issue will be resolved.  We are scrambling to get you good guidance and to address the issue.  Management in the marketing team and product team on both the SQL Azure team and Entity Framework know about the issue and your comments.  Thanks for your patience and feedback.

  • Wayne, thanks for commenting... so when do you expect guidance on this?  We've got a high volume solution out based on EF4 and SQL Azure and we love it to bits... but, the customers are experiencing this problem regularly.  What should we do in the meantime?  We've overridden SaveChanges and implemented a basic retry logic based off the SQLConnection but it's not perfect and some are calling for a switch to NHibernate.

  • Mike, this is Steve Yi from the product management team.  Send me mail at: steveyi at microsoft dot com. I'll do my best to connect you with the engineering or support teams.

  • Does anyone know the status on this issue?

  • I would also be interested in knowing...

  • I would like to know how seamless EM4 is with SQL Azure and this Retry issue, is anything been fixed by MS and where could I get that link?

  • Hey Microsoft, we are waiting! Give us guidance here, rather than asking for individual email contacts, please. We all wanna know it!

  • Great post, Steve, but what about partitioning? What is a recommended way to maintain it on SQL Azure and Entity Framework? Should it be handled manually, or Microsoft have plans to provide developers with some out of the box solution?

  • Hi Steve

    any news with connection retries and the entity framework? Thanks,


Page 1 of 1 (15 items)
Leave a Comment
  • Please add 4 and 7 and type the answer here:
  • Post