Welcome to MSDN Blogs Sign in | Join | Help

Browse by Tags

All Tags » Entity Framework   (RSS)
Tip 42 – How to create a dynamic model using Code-Only
Background: When we give examples of how to use Code-Only we always start with a strongly typed Context derived from ObjectContext . This class is used to bootstrap the model. For example this (property bodies omitted for simplicity sake): public class Read More...
Tip 41 – How to execute T-SQL directly against the database
Sometimes you’ll find you need to issue a query or command that the Entity Framework can’t support. In fact this problem is common to most ORMs, which is why so many of them have a backdoor to the database. The Entity Framework has a backdoor too… .NET Read More...
Tip 40 – How to materialize presentation models via L2E
Problem: Imagine that you have these entities public class Product { public int ID { get; set; } public string Name { get; set; } public virtual Category Category { get; set; } } public class Category { public int ID { get; set; } public string Name { Read More...
Tip 39 – How to set overlapping Relationships – EF 4.0 only
Scenario: In EF 4 we have FK relationships , available for the first time in .NET 4.0 Beta 2, so it is now possible to have a model something like this: public class Division { public int DivisionID {get;set} // Primary Key public string Name {get;set;} Read More...
Code-Only best practices
There have been lots of posts on the EFDesign blog talking about how the features in Code Only have evolved. But very little covering what we think will be the best way to write the code. You may have seen code like this: var prodConf = builder.Entity<Product>(); Read More...
Tip 33 – How cascade delete really works in EF
Imagine that in your database you have a cascade delete on an FK relationship. Something like this: Here the Delete Rule says that when a Category is deleted all the related Products should be deleted too. If you generate an EF model from this database Read More...
Tip 32 – How to create a database from SSDL – EF 4 only
We recently released a CTP that extends EF 4 Beta 1 which included Code Only. You can read more about Code Only here , here and here . If you look at the walkthroughs for Code Only you will see code that looks something like this: // Create a builder Read More...
Tip 31 – How to compose L2O and L2E queries
Imagine you want to write a query like this: var possibleBuyers= from p in ctx.People where p.Address.City == “Sammamish” && InMarketForAHouse(p) select p; Now theoretically this is possible so long as there is a SQL translation for InMarketForAHouse. Read More...
Tip 30 – How to use a custom database function
Imagine you have a database function like the DistanceBetween function in Nerd Dinner : CREATE FUNCTION [dbo].[DistanceBetween]( @Lat1 as real, @Long1 as real, @Lat2 as real, @Long2 as real) RETURNS real AS BEGIN … END And you want to use it with the Read More...
Tip 27 – How to Implement BeforeSave Validation
It is common to want to validate that your entities are ‘valid’ before you save them to the database. A naive form of validation might be to try to ensure that your entities are ‘valid’ before you add them to the context, but this doesn’t help you if Read More...
New EF blogger – Craig Lee
Short one this time. Craig Lee , a colleague of mine who works on the tools team, has just started blogging. He already has a number of posts, including an interesting one on keyboard shortcuts . Enjoy. Read More...
Tip 26 – How to avoid database queries using Stub Entities
What are Stub Entities? A stub entity is a partially populated entity that stands in for the real thing. For example this: Category c = new Category {ID = 5}; is a stub entity. It has only the ID populated, which indicates this is a stub for Category Read More...
Wrapping Providers
For well over a year now I've been talking about how it is possible with EF to write a provider that sits between the EF and the native database provider. There are lots of reasons why you might do this. Here are some examples, you could write a: Tracing Read More...
Tip 25 – How to Get Entities by key the easy way
Sometimes rather than writing this: var customer = ctx.Customers.First(c => c.ID == 5); You would rather write something like this: var customer = ctx.Customers.GetCustomerById(5); In .NET 4.0 this would be trivial to do by modifying the T4 templates Read More...
Tip 22 - How to make Include really Include
This is 22nd post in my ongoing series of Entity Framework Tips . If you want to do eager loading with the Entity Framework it is generally really easy, you simply write something like this: var results = from post in ctx.Posts.Include(“Comments”) where Read More...
More Posts Next page »
Page view tracker