Summary

Entity Framework provides a lot of value to the developers, allowing them to use C# or VB.NET code to manipulate database data. However, sometimes we have to drop a level lower, accessing data a bit more directly through views, dynamic SQL statements and/or stored procedures. We can use the ExecuteSqlCommand method to execute any arbitrary SQL code, including raw SQL or stored procedure. We can use the SqlQuery method to retrieve data from a view, stored procedure, or any other SQL statement, and Entity Framework takes care of materializing the data for us, based on the result type we provide. It is important to follow best practices when providing parameters to those two methods to avoid SQL injection vulnerability.

Entity Framework also supports environments where there are requirements to perform all updates to entities via stored procedures. The framework will even write them for us, and we would only need to write one line of code per entity for this type of support, assuming we are happy with naming conventions and coding standards for such procedures.

Entity Framework now provides support for asynchronous operations, including both query and updates. Developers must take care when using such techniques to avoid potential performance implications. In some technologies, the asynchronous API fits really well, the Web API being a good example.

We must always take care of our data, avoiding data loss at all costs. This is where concurrency handling built into Entity Framework comes in. It allows us to provide users with appropriate feedback, while helping us to avoid silent data loss. We just need to mark a property as concurrency check property, and Entity Framework will throw an exception when two users make changes to the same entity at the same time. We just need to handle this exception and provide users with an application-specific error message.

In the next chapter, we will conclude our discussion of Entity Framework by learning how to update production database structure without data loss using, migrations.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.226.251.206