background preloader

Entity Framework

Facebook Twitter

Alternate Technologies

CLR Method to Canonical Function Mapping. EDM: Mapping two entities from single table. Everythings always more complicated than it originally appears - if it looks easy, it's tough, if it looks tough, it's damn near impossible.

EDM: Mapping two entities from single table

Anyway... 1) The complex type won't work - I really like them, don't get me wrong, but they're not first class objects within the context of the framework because they can't participate in relationships - they're a great way to encapsulate dumb data but they're basically nested class definitions, not sibling classes that can be composed together 4) I have to work this out on paper, but I think this is a serious issue WRT the object model that will be used by developers - TPH inheritance et al only seem to address the inheritence side of OOD, i.e. the static relations between types - it doesn't help at all with composition, which is exactly what I need to accomplish here.

Persistence Ignorance in the Entity Framework. Well, this is certainly a big topic, and let me reassure you that it is something we have thought a lot about and are designing for in the long-term.

Persistence Ignorance in the Entity Framework

Given the timeframes involved and the scope of the entity framework, one big challenge has been to put together a long-term design that will get us where we want to go and then figure out how to deliver something of value in our first release that we can build on to get toward the final vision over the course of more than one release. I think we're on track for that.

This is less than ideal, but it's the reality that we live in. (Or at least that I live in. Maybe there are others out there who have a less constrained world--good for them!) To address the two specific concerns: 1) The requirement that entity classes inherit from a single base class: 2) The requirement to attach attributes to properties on your entity objects: The second abstraction opportunity is between the data classes (your objects) and the conceptual schema. p32-column-seligman.pdf (application/pdf Object) ADO.NET Entity Framework - LINQ. Getting Started. Getting started with LINQ to Entities is relatively easy :-) Calling ObjectContext.CreateQuery<T> gives you back a ObjectQuery<T>.

ADO.NET Entity Framework - LINQ. Getting Started.

ObjectQuery<T> is IQueryable<T> and so we can use it for LINQ queries. That means that using a plain old Vanilla ObjectContext we can write queries such as; using (ObjectContext ctx = new ObjectContext("Name=NorthwindEntities3")) { var query = from s in ctx.CreateQuery<Shipper>("NorthwindEntities3.Shippers") where s.CompanyName == "Speedy Express" select s; foreach (Shipper s in query) { System.Console.WriteLine(s.ShipperID); } } Or, given that if I've used the tooling to produce a derived NorthwindContext or similar which has a property called Shippers on it then I can shorten that down to; using (NorthwindContext ctx = new NorthwindContext()) { var query = from s in ctx.Shippers where s.CompanyName == "Speedy Express" select s; foreach (Shipper s in query) { System.Console.WriteLine(s.ShipperID); } } and so begins a journey off into LINQ.

ADO.NET Entity Framework - Bringing Together A Few Previous Posts. This is just a convenience - links to the posts that I've made so far around beta 2 of the ADO.NET Entity Framework.

ADO.NET Entity Framework - Bringing Together A Few Previous Posts

The Overview Video Entity Framework - Overview Video Note: This is also available on my Live SkyDrive in 5 pieces if that helps. "Getting Up and Running" Posts. Data Points: ADO.NET Entity Framework Overview. New information has been added to this article since publication.

Data Points: ADO.NET Entity Framework Overview

Refer to the Editor's Update below. Data Points. Dynamic Queries in Entity Framework using Expression Trees. Most of the queries you do in your application are probably static queries.

Dynamic Queries in Entity Framework using Expression Trees

The parameters you set on the query probably change, but the actual query itself doesn't. That's why compiled queries are so cool, because you can pre-compile and reuse a query over and over again and just vary the parameters (see my last blog for more information). But sometimes you might need to construct a query at runtime. By this I mean not just changing the parameter values, but actually changing the query structure. A good example of this would be a filter, where, depending on what the user wants, you dynamically create a query that culls a set down to what the user is looking for. A good example of this is file searching. My first foray into creating dynamic queries is a bit less ambitious than the above example, however. The most boring approach is, of course, to get each Tag out of the database individually with its own query (the "get each Tag individually" approach): C# - Entity Framework - Using Transactions or SaveChanges(false) and AcceptAllChanges()

Enumerate properties of an Entity Object. LINQ to Entities: Combining Predicates - meek. Someone asked a great question on the ADO.NET Entity Framework forums yesterday: how do I compose predicates in LINQ to Entities?

LINQ to Entities: Combining Predicates - meek

I’ll give three answers to the question. Answer 1: Chaining query operators Basically, you have some query and you have some predicates you want to apply to that query (“the car is red”, “the car costs less than $10”). If both conditions need to be satisfied, you can just chain together some calls to Where (“the car is red and costs less than $10”): Expression<Func<Car, bool>> theCarIsRed = c => c.Color == "Red"; Expression<Func<Car, bool>> theCarIsCheap = c => c.Price < 10.0; IQueryable<Car> carQuery = …; var query = carQuery.Where(theCarIsRed).Where(theCarIsCheap); If you’re willing to exceed the $10 budget for cars that are red, you can chain Unions instead (“the car is red or the car costs less than $10”): var query2 = carQuery.Where(theCarIsRed).Union(carQuery.Where(theCarIsCheap)); Answer 2: Build expressions manually Answer 3: Composing Lambda Expresions.

Entity Framework messes up Primary Keys of Views - A work around.