Sign in
Meta-Me
Translate This Page
Translate this page
Powered by
Microsoft® Translator
Tags
.NET 4.0
Architecture
ASP.NET
Associations
Astoria
Authentication
C#
Char
CLR
Code Only
Community
CQRS
Data 2.0
Data Availability
Data Services
Data Services Client
Debugging
Decisions
Design
Designer
DSP
Eager Loading
EDM
EF
EF 3.5
EF 4.0
EF Internals
EF Providers
Entity Framework
Entity SQL
Enums
Escher
Expressions
Extension Methods
FantasySoccer
File Systems
Finds
Fixed Length
Fixup
FK Associations
Fluent APIs
Foreign Keys
Functional
Guidance
Hyperdata
IDataServiceMetadataProvider
IDataServiceQueryProvider
IDataServiceUpdateProvider
Independent Associations
Instincts
Intent
IQueryable
IServiceProvider
JQuery
JSON
Lambda
LazyLoading
Learning
Links
LINQ
LINQ to Entities
Linq to Objects
LINQ to SQL
Mapping
Mental Model
Metadata
Monad
Musings
MVC
NChar
Object Services
ObjectQuery
OData
Optimistic Concurrency
Partial Class
Performance
Philosophical
Pluralization
POCO
Principles
Ramblings
RDF
Reflection Provider
Relationships
REST
Samples
Self-Tracking Entities
Sharepoint
SOA
SOAP
Specifications
SSDL
Statement Expression
StronglyTyped
T4
TechEd2010
Tips
Tricks
Walkthru
WCF
Browse by Tags
MSDN Blogs
>
Meta-Me
>
All Tags
>
entity framework
Tagged Content List
Blog Post:
Tip 55 - How to extend an IQueryable by wrapping it.
Alex D James
Over the last couple of years I’ve found myself in lots of situations where I’ve wanted to get ‘under the hood’ and see what is happening inside an IQueryable, but I haven’t had an easy solution, at least until now. Getting down and dirty like this is interesting because it means you can: Log...
on
1 Mar 2010
Blog Post:
Creating a Data Service Provider – Part 8 - Relationships
Alex D James
In parts 1 thru 7 we made a Read / Write typed data service provider, although it was a little simplistic because it didn’t have relationships. So lets rectify that right now by adding a relationship to make this more 'real-world' Changes to our Classes If you remember from Part 3 we had just a Product...
on
23 Feb 2010
Blog Post:
Tip 51 – How to load EF metadata from arbitrary streams
Alex D James
In Tip 45 I showed you how to build a connection string at runtime, which is pretty nifty. The problem with that was that it relies on having metadata files (.csdl .ssdl and .msl) on local disk. But what if they live on a web-server or something and you don’t even have access to the local file...
on
26 Jan 2010
Blog Post:
Custom Data Service Providers
Alex D James
Introduction Data Services sits above a Data Service Provider, which is responsible for interacting with the underlying Data Source on behalf of the Data Service. Data Services ships with some internal providers, and makes it possible for you to create custom providers too. So the obvious question...
on
7 Jan 2010
Blog Post:
Tip 47 – How fix-up can make it hard to change relationships
Alex D James
Problem: Take this code: Category oldCategory = ctx.Categories .Include("Products") .First(c => c.Name == "Drink"); Category newCategory = new Category {Name = "Beverage"}; foreach(Product product in oldCategory.Products) { newCategory.Products.Add(product); } Ignore for a second that in...
on
1 Dec 2009
Blog Post:
Tip 46 – How to exclude a property using Code-Only
Alex D James
This time a real simple one prompted by this question on StackOverflow. Problem: If you tell the Entity Framework about this class using Code-Only, by default every property becomes part of Entity, and as a result stored in the database. Usually this is what you want. But not always, imagine this class...
on
29 Nov 2009
Blog Post:
Tip 45 – How to swap EF metadata at runtime.
Alex D James
Background By default the Entity Framework embeds its metadata inside your assembly as a resource. It also puts a connection string in the App or Web Config that references those resources something like this: <add name="BloggingEntities" connectionString="metadata=res://*/Blogging.csdl|res://*/Blogging...
on
29 Nov 2009
Blog Post:
Tip 42 – How to create a dynamic model using Code-Only
Alex D James
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 MyContext : ObjectContext { public ObjectSet<Category>...
on
9 Nov 2009
Blog Post:
Tip 41 – How to execute T-SQL directly against the database
Alex D James
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 3.5 SP1 In .NET 3.5 SP1 you can get to the underlying...
on
7 Nov 2009
Blog Post:
Tip 40 – How to materialize presentation models via L2E
Alex D James
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 { get; set; } public virtual List<Product> Products...
on
7 Nov 2009
Blog Post:
Tip 39 – How to set overlapping Relationships – EF 4.0 only
Alex D James
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;} public virtual List<Lawyer> Lawyers {get;set;...
on
1 Nov 2009
Blog Post:
Code-Only best practices
Alex D James
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>(); productConf.HasKey(p => p.Id...
on
13 Oct 2009
Blog Post:
Tip 33 – How cascade delete really works in EF
Alex D James
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 you get a model that on the surface looks no different...
on
18 Aug 2009
Blog Post:
Tip 32 – How to create a database from SSDL – EF 4 only
Alex D James
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 and configure it var builder = new ContextBuilder<MyContext>...
on
11 Aug 2009
Blog Post:
Tip 31 – How to compose L2O and L2E queries
Alex D James
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. In EF 4.0 you do this by creating a CLR stub...
on
11 Aug 2009
Blog Post:
Tip 30 – How to use a custom database function
Alex D James
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 Entity Framework. Declaring the Function...
on
6 Aug 2009
Blog Post:
Tip 27 – How to Implement BeforeSave Validation
Alex D James
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 you pass through ‘invalid’ states, i.e. as you build...
on
20 Jul 2009
Blog Post:
New EF blogger – Craig Lee
Alex D James
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.
on
19 Jun 2009
Blog Post:
Tip 26 – How to avoid database queries using Stub Entities
Alex D James
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 5. When are Stub Entities Useful...
on
19 Jun 2009
Blog Post:
Wrapping Providers
Alex D James
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 Provider Auditing Provider Caching Provider Query...
on
12 Jun 2009
Blog Post:
Tip 25 – How to Get Entities by key the easy way
Alex D James
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 that do code gen. You would simply...
on
11 Jun 2009
Blog Post:
Tip 22 - How to make Include really Include
Alex D James
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 post.Author.EmailAddress == “alexj@microsoft...
on
2 Jun 2009
Blog Post:
Tip 21 – How to use the Single() operator – EF 4.0 only
Alex D James
This is 21st post in my ongoing series of Entity Framework Tips , and the first that is specific to EF 4.0. Entity Framework 4.0 Beta 1 As you’ve probably heard VS 2010 Beta 1 is now available to subscribers which means some of you can get your hands on EF 4.0 Beta 1 too. If you have any questions our...
on
21 May 2009
Blog Post:
Tip 20 – How to deal with Fixed Length Keys
Alex D James
This is 20th post in my ongoing series of Entity Framework Tips . Fixed Length Field Padding: If you have an fixed length column in the database, for example something like NCHAR(10) when you do an insert, padding happens automatically. So for example if you insert ‘12345’ you get 5 spaces automatically...
on
20 May 2009
Blog Post:
Tip 19 – How to use Optimistic Concurrency with the Entity Framework
Alex D James
This is the 19th post in my ongoing series of Entity Framework Tips . Background: If you have a table with a timestamp column, and you reverse engineer an Entity from that table, you will end up with a Binary property in your entity (in my example called Version). If you look at the properties...
on
19 May 2009
Page 1 of 2 (40 items)
1
2