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
>
tips
Tagged Content List
Blog Post:
Tip 56 - Writing an OData Service using the Reflection Provider
Alex D James
At TechEd I got a lot of questions about how to expose Data as OData By now you probably know you can use Data Services and the Entity Framework to expose data from a database as an OData Service. You might even know you can use Data Services with a custom Data Service Provider to expose arbitrary...
on
11 Jun 2010
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:
Tip 54 – How to improve performance using Statement Expressions
Alex D James
Background: While writing the update post in my Data Service Provider series I ended up writing this block of reflection code to copy properties values from one object to another: foreach (var prop in resourceType .Properties .Where(p => (p.Kind & ResourcePropertyKind.Key) != ResourcePropertyKind...
on
13 Feb 2010
Blog Post:
Tip 53 – How to debug EF POCO mapping issues
Alex D James
If you are trying to use POCO classes in EF 4.0, it is relatively easy to run into problems with the mapping from your model to your CLR classes. If you get any nasty problems here, the best way to get to the bottom of things is to try to explicitly load the metadata for your POCO types. For example...
on
11 Feb 2010
Blog Post:
Tip 52 – How to re-use Types with the Data Services client
Alex D James
By default when you add a Data Service Service Reference you get automatic code-generation, which produces a strongly typed DataServiceContext and classes for all your ResourceTypes. You can have a look at this generated code if you ‘show all files’ in your project: And then expand your Data...
on
27 Jan 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:
Tip 50 – How to query a Data Service using JQuery
Alex D James
Recently I’ve been spending some of my time playing with JQuery . And because Data Services can expose data in JSON format, I thought I’d use JQuery to grab some data from a Data Service. Turns out it is pretty simple. This example isn’t going to win any beauty awards, but it will show you the...
on
18 Jan 2010
Blog Post:
Tip 49 – How to find your Data Service bug
Alex D James
I’ve been playing around with creating a custom Astoria Data Service Provider , aka DSP, for a while now. So far I’d managed to get my metadata all setup, so browsing to $metadata works great. I’d got a few simple queries work. Basically everything was going fine. At least until I tried this URL: I wasn...
on
11 Dec 2009
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 44 – How to navigate an OData compliant service
Alex D James
I recently did a crash course in Data Services and OData . While doing so I realized my notes might be useful for you guys. So here is my little cheat sheet to quickly get up to speed with OData Urls. Note: OData Services may not necessarily support all of the following features: but if they do, this...
on
18 Nov 2009
Blog Post:
Tip 43 – How to authenticate against a Data Service
Alex D James
Problem: When writing code against a Data Service, like say SharePoint , the client application must provide a valid set of credentials, or you will see a dreaded “401 Unathorized” response. For Silverlight applications hosted on the same site as the DataService, this is generally handled for you...
on
13 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:
Tip 38 – How to use CodeOnly with Astoria
Alex D James
The normal way that you create an ADO.NET Data Services (aka Astoria) Service is by creating a class that derives from DataService<T>. public class BloggingService : DataService<BloggingEntities> And if you want to use Entity Framework under the hood the T you supply must derive from...
on
14 Oct 2009
Blog Post:
Tip 37 – How to do a Conditional Include
Alex D James
Problem Someone asked how to do a Conditional Include a couple of days ago on StackOverflow. They wanted to query for some entity (lets say Movies) and eager load some related items (lets say Reviews) but only if the reviews match some criteria (i.e. Review.Stars == 5). Unfortunately though this isn...
on
12 Oct 2009
Blog Post:
Tip 36 – How to Construct by Query
Alex D James
While writing my tips series and writing EF controllers for MVC I found that I regularly wanted to create and attach a stub entity . Unfortunately it isn’t quite that simple, you have to make sure the entity isn’t already attached first, otherwise you’ll see some nasty exceptions. To avoid these exceptions...
on
23 Sep 2009
Blog Post:
Tip 35 – How to write OfTypeOnly<TEntity>()
Alex D James
If you write a LINQ to Entities query like this: var results = from c in ctx.Vehicles.OfType<Car>() select c; It will bring back, Cars and any type that derives from Car, like say SportCar or SUV. If you just want Cars and you don’t want derived types like SportCars or SUVs in LINQ to...
on
17 Sep 2009
Blog Post:
Tip 34 – How to work with Updatable Views
Alex D James
UPDATE: thanks Zeeshan for pointing out that by default only non-nullable columns end up in the key for view backed entities. Imagine this situation, you have a view in your database, and it is updatable. Next you decide to use this view with the Entity Framework, so you go ahead and import it. The resulting...
on
1 Sep 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
Page 1 of 3 (58 items)
1
2
3