background preloader

Entity Framework

Facebook Twitter

Migrations

Solving the “No logical space left to create more user strings” Error and Improving performance of Pre-generated Views in Visual Studio .NET4 Entity Framework - Windows Server AppFabric Customer Advisory Team. As shown in the previous precompiled view blog (Isolating Performance with Precompiled/Pre-generated Views in the Entity Framework 4), views can significantly improve performance in various scenarios such as first-run; memory usage; and execution of one-off queries.

Solving the “No logical space left to create more user strings” Error and Improving performance of Pre-generated Views in Visual Studio .NET4 Entity Framework - Windows Server AppFabric Customer Advisory Team

However, the creation of views for large complex models that consist of many entities and associations), can create lots of views which in turn will require heavy use of strings, and reach the .NET metadata format limit on the number of user string characters (0xFFFFFF). Hence when trying to compile a project leveraging this type of views, the following compile error will occurred. Error 1 Unexpected error writing metadata to file 'D:\Compile view fix\... \PerfSample.exe' -- 'No logical space left to create more user strings.' For ease of reading, it is recommended to review the previous post on pre-generated views.

Analysis Design Approach Here is where the number of user strings characters can reach the compiled limits. EDMGEN ViewGeneration takes hours. We're using code-first with 500+ entities.

EDMGEN ViewGeneration takes hours

For building pre-generated views we perform the following steps: - create an edmx file using EdmxWriter - split the edmx file into ssdl/csdl/msl files - build pre-generated views using edmgen.exe /mode:ViewGeneration This last step, the edmgen.exe, takes more than 24 hours. Maybe the following is a hint: I examined the process using Visual Studio profiler.

Splitting the model into smaller parts is not an option. Is it possible to simplify the created edmx file, but still getting the same views? Performance Considerations (Entity Framework) This topic describes performance characteristics of the ADO.NET Entity Framework and provides some considerations to help improve the performance of Entity Framework applications.

Performance Considerations (Entity Framework)

Stages of Query Execution In order to better understand the performance of queries in the Entity Framework, it is helpful to understand the operations that occur when a query executes against a conceptual model and returns data as objects. The following table describes this series of operations. 1 When a data source provider implements connection pooling, the cost of opening a connection is distributed across the pool. LINQ To SQL LIKE Operator - Generating LIKE in SQL Server Statements. Tracing SQL Statements generated by Entity Framework « devioblog. The DataContext of Linq2Sql provides a Log property that one can assign a TextWriter to retrieve the text of the SQL statements generated by Linq.

Tracing SQL Statements generated by Entity Framework « devioblog

The ObjectContext of Entity Framework does not contain such an easy way to trace generated SQL statements. An MSDN blog provides a solution in the form of an Entity Framework provider which simply wraps the existing EF data provider. Integration into an existing project is pretty simple and straight forward (see detailed discussion on MSDN): Register Provider Factories in web.config or app.configDerive a class (ExtendedEntities) from the generated Entities classUse the ExtendedEntities class throughout the code To be able to switch between logging and non-logging code, I found it helpful to modify this approach a bit. First, all “extended” functionality is activated in the code using a #define symbol.

Second, the tracing functionality will only be activated if the config file contains an AppSetting named “EFTraceDir”. to a factory pattern. Stored procedures with output parameters using SqlQuery in the DbContext API - Diego Vega. The DbContext API introduced in Entity Framework 4.1 exposes a few methods that provide pass-through access to execute database queries and commands in native SQL, such as Database.SqlQuery<T>, DbSet<T>.SqlQuery, and also Database.ExecuteSqlCommand.

Stored procedures with output parameters using SqlQuery in the DbContext API - Diego Vega

These methods are important not only because they allow you do execute your own native SQL queries but because they are right now the main way you can access stored procedures in DbContext, especially when using Code First. Implementation-wise these are just easier to use variations of the existing ObjectContext.ExecuteStoreQuery<T> and ObjectContext.ExecuteStoreCommand that we added in EF 4.0, however there still seems to be some confusion about what these methods can do and in particular about the query syntax they support. I believe the simplest way to think about how these methods work is this: For a stored procedure that returns the necessary columns to materialize a Person entity, you can use syntax like this:

Code-First Development with Entity Framework 4. .NET 4 ships with a much improved version of Entity Framework (EF) – a data access library that lives in the System.Data.Entity namespace.

Code-First Development with Entity Framework 4

When Entity Framework was first introduced with .NET 3.5 SP1, developers provided a lot of feedback on things they thought were incomplete with that first release. The SQL team did a good job of listening to this feedback, and really focused the EF that ships with .NET 4 on addressing it. Some of the big improvements in EF4 include: POCO Support: You can now define entities without requiring base classes or data persistence attributes.Lazy Loading Support: You can now load sub-objects of a model on demand instead of loading them up front.N-Tier Support and Self-Tracking Entities: Handle scenarios where entities flow across tiers or stateless web calls.Better SQL Generation and SPROC support: EF4 executes better SQL, and includes better integration with SPROCsAutomatic Pluralization Support: EF4 includes automatic pluralization support of tables (e.g.

Issuing SQL in Entity Framework. Practical .NET Issuing SQL in Entity Framework If you're considering a move into the world of LINQ and Entity Framework, you have to consider the possibility that LINQ and Entity Framework won't let you issue some bizarrely complicated SQL statement.

Issuing SQL in Entity Framework

Don't worry -- should that ever happen, you have options. If you worry that your data access requirements are sufficiently "interesting" that LINQ and Entity Framework can't do the job, the good news is that you can always use plan old SQL. Updates in Entity Framework. Practical .NET Updates in Entity Framework A primer on how to update objects, including adds and deletes, in the Entity Framework.

Updates in Entity Framework

Having just done a column on how LINQ + Entity Framework (EF) makes typical database activities in business applications, I realized that I'd concentrated entirely on retrieving data and ignored doing updates. There's a reason for that: LINQ doesn't do updates. Some Bumps in the Separation of Entity Framework and .NET Framework. Some Bumps in the Separation of Entity Framework and .NET Framework It's almost like a feuding spouse who leaves the partner only to find out how much they're missed and decides not to cut ties completely and maybe hang out with each other now and then.

Some Bumps in the Separation of Entity Framework and .NET Framework

Entity Framework Developers Clamor for Better SQL Generation. Entity Framework Developers Clamor for Better SQL Generation "I have seen simple select statements [in Entity Framework] with 4 or 5 includes result in nearly 5,000 line SQL statements when an equivalent hand-written SQL statement is [about] 15 lines.

Entity Framework Developers Clamor for Better SQL Generation

" So reads the first of 21 comments on Microsoft's "ADO.NET Entity Framework (EF) Feature Suggestions" site, where developers can post, vote and comment on proposed EF enhancements. "Improved SQL Generation" is by far the No. 1 feature suggestion, with some 1,400 votes. Several developer complaints about SQL generation concerned bloated code or slow performance.

You saw an example of the former; the latter is exemplified by this comment: "I just documented a case where the Contains() operator reduces EF query performance by a factor of 300. An EF Code First Tutorial. Code Focused An EF Code First Tutorial Code First frees you up from the chore of creating databases for your project. Here's a primer on how to do it.

By Sam Nasr03/07/2012 Get Code Download Entity Framework has been the latest buzzword in the Microsoft Development circle since the release of Visual Studio 2010. The first step to working with a database is to create the database. Database First: Importing an existing database into the EF Model Model First: Creating the model and using it to generate the database Code First: Using code classes to generate the database. EF 4.3 Beta 1: Code-Based Migrations Walkthrough - ADO.NET team blog. The information in this post is out of date. Visit msdn.com/data/ef for the latest information on current and past releases of EF. For Code First Migrations see. Entity Framework 4 POCO, Repository and Specification Pattern [Upgraded to EF 4.1] « Huy Nguyen's Blog. Downloads - ef4prs - Entity Framework 4 POCO, Repository & Specification Pattern. Requirements for Creating POCO Proxies (Entity Framework 4.1)

Working with Self-Tracking Entities. [This topic is pre-release documentation and is subject to change in future releases. Blank topics are included as placeholders.] RC of Entity Framework 4.1 (which includes EF Code First) Last week the data team shipped the Release Candidate of Entity Framework 4.1. You can learn more about it and download it here. EF 4.1 includes the new “EF Code First” option that I’ve blogged about several times in the past.

EF Code First provides a really elegant and clean way to work with data, and enables you to do so without requiring a designer or XML mapping file. Below are links to some tutorials I’ve written in the past about it: The above tutorials were written against the CTP4 release of EF Code First (and so some APIs might be a little different) – but the concepts and scenarios outlined in them are the same as with the RC. Go Live License. RC of Entity Framework 4.1 (which includes EF Code First) EF 4.1 Release Candidate Available - ADO.NET team blog. The information in this post is out of date. Visit msdn.com/data/ef for the latest information on current and past releases of EF. We are excited to announce that Microsoft ADO.NET Entity Framework 4.1 Release Candidate (EF 4.1 RC) is now available.

This is a fully supported, go-live release. In approximately one month we plan to release the final Release to Web (RTW). We are not planning any changes to the API surface or behavior between RC and RTW, the release is purely to allow any new bugs found in the RC build to be evaluated and potentially fixed. Maintenance-Free Mocking for Unit Testing with Entity Framework 4.0. If you are trying to unit test in Entity Framework 4.0, you may have come across an apparent lack of architectural support for unit testing integration. Visual Studio 2010 appears to have excellent support for integrating Unit Test Projects into your solution, but no out-of-the box integration for using an Entity Framework Data Model (EDMX) generated Object Context is provided. This article discusses how to implement a Mocking based approach to Unit Testing in a way that requires zero future code maintenance; generated automatically from the EDMX.

The implementation doesn't require anything more than Visual Studio 2010. Walkthrough: Test-Driven Development with the Entity Framework 4.0 - ADO.NET team blog. This walkthrough will demonstrate how to use the new Plain Old CLR Object (POCO) support in Entity Framework 4.0 to develop an application using Test-Driven Development (TDD). In the first release of EF, entity classes had to inherit from EntityObject or implement one of the EF interfaces, which meant your classes had to have direct dependencies on the EF.

As a result, writing unit tests that verified the logic for just your domain objects was challenging. The tests would have to interact with the database directly, which violates the principle of persistence ignorance, and results in the tests running orders of magnitude slower. Putting Entity framework 4 to use in a business architecture « Daniel Wertheim. Updates have been made since version 1 of this article! Include() Extension Method and POCO. Entity Framework Include with Func next - Matthieu MEZIL. Compiled Queries in Entity Framework. I was fiddling with compiled queries yesterday and thought I would share what I saw as results. This is anything but laboratory benchmark testing so take it for what it’s worth.

I did only a very simple query to start with, finding SalesOrders whose total is greater than a given number. Using Repository and Unit of Work patterns with Entity Framework 4.0 - ADO.NET team blog. The information in this post is out of date. Visit msdn.com/data/ef for the latest information on current and past releases of EF. POCO in the Entity Framework: Part 1 - The Experience - ADO.NET team blog. Agile Entity Framework 4 Repository: Part 1- Model and POCO Classes. I’m going to lay out this out in a few blog posts because it’s complex. As I am not a TDD developer, I won’t be starting from the tests. Agile Entity Framework 4 Repository: Part 1- Model and POCO Classes.