background preloader


Facebook Twitter

Entity Framework Performance and What You Can Do About It - Simple Talk. Compared to writing your own SQL to access data, you can become miraculously more productive by using Entity Framework (EF).

Entity Framework Performance and What You Can Do About It - Simple Talk

Unfortunately, several traps that are easy to fall into have given it a reputation for performing poorly; but it doesn’t have to be this way! The performance of Entity Framework may once have been inherently poor but isn’t any more if you know where the landmines are. In this article we’ll look at where these ‘traps’ are hiding, examining how they can be spotted and what you can do about them. We’ll use examples from a simplified school management system. There’s a database with two tables for Schools and their Pupils, and a WinForms app using an EF code-first model of this database to fetch data in a variety of inefficient ways.

To play along at home, you can grab the code for most of these examples from – setup instructions are included in the readme. Database access. A LINQ extension method to calculate a running total - The other day I needed to calculate a running balance based on a series of either debit or credit transactions.

A LINQ extension method to calculate a running total -

So each line item contains a balance column that is the carried forward balance plus the sum of debits and credits up until the current line item. After some playing around I came up with a simple LINQ expression to do the job. It is also a nice illustration of how LINQ expression trees enable you to create more elegant solutions. Rollup Extension Method: Create Running Totals using LINQ to Objects - Eric White's Blog. Recently, I had need for a new extension method for IEnumerable<T>, which I call "Rollup".

Rollup Extension Method: Create Running Totals using LINQ to Objects - Eric White's Blog

This extension method is sort of a cross between the Select and Aggregate extension methods. Like Select, when using this extension method you write a lambda expression to project the new value in a new collection. Unlike Select, in the projection lambda expression, you are passed the projected value for the immediately preceding element.

The previous value for the first element in the projected collection is a seed value that you pass to the Rollup extension method. SQL Joins with C# LINQ. Posted By : Shailendra Chauhan, 18 Oct 2012 Updated On : 25 Nov 2013 Keywords : linq join on multiple conditions,c# join example, linq inner join with multiple conditions, linq left outer join, linq left join, linq cross join, linq right join, linq group join.

SQL Joins with C# LINQ

SQL Joins with C# LINQ. RiggsHill Software. There are two flavors of serialization you can use on Framework entities: good ol' XML serialization and the DataContract serialization.

RiggsHill Software

XML serialization is pretty straightforward - it serializes the object it's given. But it does not walk references (I'm talking foreign keys here) or collections. whereas the DataContract serializer does handle the references and keeps track of what objects have been serialized and what hasn't. If you're going to use XSLT on the serialization, I'm not sure at this point which one is better - they're probably equal but time will tell. Unfortunately you can't directly serialize the entire ObjectContext, only collections or individual objects can be serialized. But this isn't as bad as it sounds as usually you'll want to start at some 'master object' in a collection and serialize it and all it references, so the inability to directly serialize the Context is not a big loss. MainModule.vb. Managing BLOBs using SQL Server FileStream via EF and WCF streaming.

Public Interface IDocumentService <OperationContract()> Sub SaveDocument(documentInfo As DocumentInfo) <OperationContract()> Function GetDocumentKeysByFullText(searchCondition As String) As List(Of DocumentKeys)

Managing BLOBs using SQL Server FileStream via EF and WCF streaming

EF Code First Extras. Tracing and Caching for Entity Framework available on MSDN Code Gallery - Jaroslaw Kowalski. We have just released a sample that shows how to extend Entity Framework in interesting ways by plugging into ADO.NET provider interface.

Tracing and Caching for Entity Framework available on MSDN Code Gallery - Jaroslaw Kowalski

The sample provides two extensions: EFTracingProvider – which adds the ability to log all SQL commands that are executed (similar to LINQ to SQL’s DataContext.LogEFCachingProvider – which adds transparent query results cache to EF The sample comes with implementation of distributed cache which uses Velocity CTP 3 as well as an adapter for ASP.NET and simple in-memory cache implementation. Because the sample is quite large and uses many advanced techniques, it’s impossible to fully explain it all in one blog post.

In this first post I’ll briefly explain the idea of wrapper providers and describe the new the APIs exposed by EFTracingProvider and EFCachingProvider. Tip 14 - How to cache Entity Framework Reference Data - Meta-Me. Scenario: In order to make applications perform it makes a lot of sense to cache commonly used reference data.

Tip 14 - How to cache Entity Framework Reference Data - Meta-Me

Good examples of reference data include things like States, Countries, Departments etc. Generally you want to have this data readily at hand, so you can populate dropdown boxes etc. A good example where caching reference data might be handy is a web page for signing up new customers, part of the form collects the customers address, including their State. In this example you need the reference data for two things: Exposing the ORM Cache. Related Content Browse this Topic: Queue on Reddit Exposing the ORM Cache Familiarity with ORM caching issues can help prevent performance problems and bugs.

Exposing the ORM Cache

In the early 1990s, when object-oriented languages emerged into the mainstream of software development, a noticeable surge in productivity occurred as developers saw new and better ways to create software programs. Доступ к данным - Second-Level Caching in the Entity Framework and AppFabric. ObjectContext и DbContext в Entity Framework (EF) поддерживают информацию о состоянии сущностей, которыми они управляют.

Доступ к данным - Second-Level Caching in the Entity Framework and AppFabric

Но, как только контекст выходит из области видимости, данная информация перестает быть доступной. Это называют кешированием первого уровня, и оно действует лишь в течение жизненного цикла транзакции. Если вы пишете распределенные приложения с применением EF, где контекст часто меняется (а значит, ваша информация о состоянии доступна не всегда), кеширование первого уровня вряд ли обеспечит ваши потребности. Такая ситуация типична для веб-приложений и сервисов — или даже когда вы используете какой-то тип реализации шаблона хранилища, где длительно выполняемый контекст недоступен. Почему EF может выиграть от кеширования второго уровня. Tracing and Caching Provider Wrappers for Entity Framework in C# for Visual Studio 2010.

Repository, Specification, Unit of Work, Persistence Ignorance POCO with Microsoft ADO.NET Entity Framework 4.0 Beta 2 « KITCHAIYONG.NET. Preface As of preparing this writing and the source codes, I was using the .NET Framework 4.0 Beta 1, Visual Studio 2010 Beta 1 and ADO.NET Entity Framework Feature CTP 1. However, the .NET Framework 4.0 Beta 2 and Visual Studio 2010 Beta 2 made their debut on 21 October 2009. I decided to upgrade the projects to this latest beta 2 version. .NET Junkie - Faking your LINQ provider part 1. Friday, someone at Stackoverflow asked how to hide LINQ enabled persistence frameworks behind an abstraction (the repository pattern). I pointed him to a question on Stackoverflow that I answered a few days earlier in what I explained how to allow your LINQ to SQL project to be unit testable. Friday’s question however, was about being able to easily change the O/RM later on, and specifically with multiple data stores / databases involved.

Let me start by saying that due to the current difference in behavior and quality between both open source and commercial LINQ provider implementations, it is hard to completely abstract away such implementation, while still allowing to use LINQ to Expression queries that are effectively translated to database queries. For the project I'm currently working on, I use LINQ to SQL as O/RM tool and I was faced with the problem of unit testing. mvc 3 - MVC, EF - DataContext singleton instance Per-Web-Request in Unity. Generic Repository Pattern - Entity Framework, ASP.NET MVC and Unit Testing Triangle. IMPORTANT NOTE: I have a new blog post about Generic Repository implementation for Entity Framework. Please check it out instead of this one: Clean, Better, and Sexier Generic Repository Implementation for Entity Framework NOTE:Entity Framework DbContext Generic Repository Implementation Is Now On Nuget and GitHub: DRY: Don’t repeat yourself which is a principle of software development aimed at reducing repetition of information of all kinds, especially useful in multi-tier architectures.

That’s what Wikipedia says. О разработке ПО и эффективности: Code First Migrations + Entity Framework 4.3 Beta 1. Mapping private/protected/… properties in Entity Framework 4.x Code First  Mapping private/protected/... properties in Entity Framework 4.x Code First More than a year ago I was blogging about how to map private/protected/... properties in Code First CTP4 for the time being. Well it a long time and a lot of changed. Advanced Data - Programming ASP.NET MVC 4 Web Applications. Testability and Entity Framework 4.0. Scott Allen Published: May 2010 Introduction This white paper describes and demonstrates how to write testable code with the ADO.NET Entity Framework 4.0 and Visual Studio 2010. This paper does not try to focus on a specific testing methodology, like test-driven design (TDD) or behavior-driven design (BDD). Mvc & jQuery CMS - The Repository Pattern with EF code first & Dependeny Injection in ASP.NET MVC3.

Introduction In these days i started use EF code first and think about how could i take the advantage form it for my recent project. My project is base on MVC3 and there are some challenges to continue update this project. At that time i must finish my job in a very shortly deadline so fast so good i just define some data access interfaces and implemented them with EF4.

There are some things in my project troubling me: Entity Framework POCO (EF4): Generic Repository and Unit of Work Prototype. POCO in the Entity Framework : Part 3 – Change Tracking with POCO - ADO.NET team blog. The information in this post is out of date. Implementing the Repository and Unit of Work Patterns in an ASP.NET MVC Application (9 of 10) The Contoso University sample web application demonstrates how to create ASP.NET MVC 4 applications using the Entity Framework 5 Code First and Visual Studio 2012. For information about the tutorial series, see the first tutorial in the series. You can start the tutorial series from the beginning or download a starter project for this chapter and start here. If you run into a problem you can’t resolve, download the completed chapter and try to reproduce your problem. You can generally find the solution to the problem by comparing your code to the completed code.

For some common errors and how to solve them, see Errors and Workarounds. In the previous tutorial you used inheritance to reduce redundant code in the Student and Instructor entity classes. The Repository and Unit of Work Patterns The repository and unit of work patterns are intended to create an abstraction layer between the data access layer and the business logic layer of an application.

Creating the Student Repository Class. ObjectContext Undo, Cancel? Developing web apps using ASP.NET MVC 3, Razor and EF Code First - Part 1 - Shiju Varghese's Blog. EF Feature CTP5: Pluggable Conventions - ADO.NET team blog. The information in this post is out of date.