background preloader

EF5

Facebook Twitter

C# - Use Entity Framework's StructuralTypeConfiguration.Ignore() to Ignore all properties but specified set. C# - Use Entity Framework's StructuralTypeConfiguration.Ignore() to Ignore all properties but specified set. C# - Entity Framework - Using Transactions or SaveChanges(false) and AcceptAllChanges() Entity Framework Fluent API - Configuring/Mapping Properties & Types. When working with Entity Framework Code First the default behavior is to map your POCO classes to tables using a set of conventions baked into EF.

Entity Framework Fluent API - Configuring/Mapping Properties & Types

Sometimes, however, you cannot or do not want to follow those conventions and need to map entities to something other than what the conventions dictate. There are two main ways you can configure EF to use something other than conventions, namely annotations or EFs fluent API. The annotations only cover a subset of the fluent API functionality, so there are mapping scenarios that cannot be achieved using annotations. Chapter 11: Server-Side Implementation. Creating a well-architected web server application requires meeting the needs of the web client while properly factoring the Microsoft® .NET Framework code on the web server.

Chapter 11: Server-Side Implementation

A web server application is responsible for more than just returning HTML content. Web server applications also involve data models, data access and storage, security, communication, resource management, and internationalization. This chapter covers ways you can integrate technologies in the Microsoft web platform into a coherent architecture that is reliable, testable, and capable of handling demanding web client applications. Entity Framework Code First Bootstrapping - Kazi Manzur Rashid. This post is primarily for my fellow friends of local .net user group who asked for a rough guideline on how to get started with the latest Entity Framework Code First, I will try to keep it short and concise.

Entity Framework Code First Bootstrapping - Kazi Manzur Rashid

I assume that it is going to be used in an ASP.NET MVC Application and behind the scene an IoC container would be used to glue everything. Before going into the implementation details there are certain design choice of mine, first persistence ignorance which means the domain model have no clue whether Entity Framework is used or any other ORM (nothing fancy here, out of the box the EF Code First has this support), next, I prefer to use class mapping which I think gives a bit more control comparing to decorating the domain classes with the data annotation attributes.

Lets starts with a typical Category, Product, Customer and Order domain. Now, lets check how the custom DbContext is implemented. Or Repository Tests like: Lazy Loading vs. Eager Loading. The Entity Framework offers several different ways to load the entities that are related to your target entity.

Lazy Loading vs. Eager Loading

For example, when you query for Products, there are different ways that the related Orders will be loaded into the Object State Manager. From a performance standpoint, the biggest question to consider when loading related entities will be whether to use Lazy Loading or Eager Loading. EF Feature CTP5: Pluggable Conventions - ADO.NET Blog. The information in this post is out of date.

EF Feature CTP5: Pluggable Conventions - ADO.NET Blog

Visit msdn.com/data/ef for the latest information on current and past releases of EF. The pluggable conventions feature was removed from the EF4.1 release. You can track this feature at. Entity Framework Code First Bootstrapping - Kazi Manzur Rashid. An Introduction To Domain-Driven Design. Best Practice An Introduction To Domain-Driven Design David Laribee Domain-Driven Design (DDD) is a collection of principles and patterns that help developers craft elegant object systems.

An Introduction To Domain-Driven Design

Properly applied it can lead to software abstractions called domain models. These models encapsulate complex business logic, closing the gap between business reality and code. In this article, I'll cover the basic concepts and design patterns germane to DDD. If the ideas presented here appeal to you, I highly recommend that you deepen your toolbox by reading the book Domain-Driven Design: Tackling Complexity in the Heart of Software, by Eric Evans. Cutting Contexts by Architectural Need Bounded Contexts needn't be organized solely by the functional area of an application. It's often desirable in such circumstances (which might occur pretty often) to break out the reporting database from the transactional database. The Platonic Model You can relate Plato's theory of Forms to DDD. The Unit Of Work Pattern And Persistence Ignorance. Patterns in Practice The Unit Of Work Pattern And Persistence Ignorance Jeremy Miller In the April 2009 issue of MSDN Magazine ("Persistence Patterns") I presented some common patterns that you will encounter when using some sort of Object/Relational Mapping (O/RM) technology to persist business entity objects.

The Unit Of Work Pattern And Persistence Ignorance

Repository pattern, done right. The repository pattern has been discussed a lot lately.

Repository pattern, done right

Especially about its usefulness since the introduction of OR/M libraries. This post (which is the third in a series about the data layer) aims to explain why it’s still a great choice. Let’s start with the definition: A Repository mediates between the domain and data mapping layers, acting like an in-memory domain object collection. Client objects construct query specifications declaratively and submit them to Repository for satisfaction. The repository pattern is used to create an abstraction between your domain and data layer. Read the abstractions part of my data layer article. The Repository Pattern. In many applications, the business logic accesses data from data stores such as databases, SharePoint lists, or Web services.

The Repository Pattern

What is Code-First? Let’s create first simple code first example.

What is Code-First?

Create the Class Library project in Visual Studio 2010. Write two simple Student and Standard entity classes as below (You can use Entity Framework 4.1/4.3/5.0 for this example.): Student Class: public class Student { public Student() { } public int StudentID { get; set; } public string StudentName { get; set; } } Standard Class: public class Standard { public Standard() { } public int StandardId { get; set; } public string StandardName { get; set; } public string Description { get; set; } } Now, create context class which is derived from DBContext class with two DbSet properties, one for Student and one for Standard. LINQ to Entities. LINQ to Entities provides Language-Integrated Query (LINQ) support that enables developers to write queries against the Entity Framework conceptual model using Visual Basic or Visual C#. Queries against the Entity Framework are represented by command tree queries, which execute against the object context.

LINQ to Entities converts Language-Integrated Queries (LINQ) queries to command tree queries, executes the queries against the Entity Framework, and returns objects that can be used by both the Entity Framework and LINQ. The following is the process for creating and executing a LINQ to Entities query: Inovex » Some Tips On Migrating from LINQ-to-SQL to Entity Framework. Inovex » Some Tips On Migrating from LINQ-to-SQL to Entity Framework.