Stuff to know when starting with ADO.NET Data Services

This post is dedicated for those who are starting with ADO.NET Data Services (formerly known as Project “Astoria”). So let us start.

You made everything how tutorial says. You checked every single line of code. But you still get:

The server encountered an error processing the request. See server logs for more details.

Probably you also have checked everywhere but failed to find these logs. If not, even do not try. This is waste of time. Anyway, solution is simple. First alter InitializeService method:

config.UseVerboseErrors = true;

And second is ServiceBehavior attribute with IncludeExceptionDetailInFaults:

[ServiceBehavior(IncludeExceptionDetailInFaults = true)]   
public class ServiceName : DataService<ExampleContext>{
	...
}

You need to do both of this. In fact I spent some of my weekend time to understand this.

Go further. Next super intuitive exception message is:

The property ‘Xxxx’ on type ‘Xxxx.Xxxxx’ is not a valid property. Properties whose types are collection of primitives or complex types are not supported.

Had I mentioned that for some reasons neither of these exceptions break Visual Studio in debug mode? It is true. Anyways, reason and solution by Pedram Rezaei. The reason is Data Services are not so clever (or simply stupid) to understand how to map complex types. So you have to help them. You have to add another root for this complex type. Suppose your Xxxx was Order. Then you have to alter your context with:

public IQueryable<Order> Orders { get { return /*Somewhere*/ } }

Should work! Well, not really! Go further:

The property ‘Xxxxx’ on type ‘Xxxx.Xxxx’ is not a valid property. Make sure that the type of the property is a public type and a supported primitive type or a entity type with a valid key or a complex type.

This is about enums in your class. Drop them out! YAGNI! You aren’t gonna need enums!

The property ‘EntityState’ on type ‘Xxxx.Xxxx’ is not a valid property. Make sure that the type of the property is a public type and a supported primitive type or a entity type with a valid key or a complex type.

Image stolen from Heavy Metal Nutcracker(http://www.mocha.uk.com/shop/index.cgi?command=moreinfo&search=TT09)

This occur when you try to use entities generated by Entity Framework in non Entity Framework context (context not derived from ObjectContext). As you may know, in Entity Framework your entities have to derive from EntityObject and this guy has enum….

Under the hood, ADO.NET DataServices is hardcoded (yes, believe or not, but it really hardcoded!) to look if context derives from ObjectContext, and if true just filter out infrastructure properties. The only solution so far is to use IgnoreProperties. Both the reason and a “solution” came from MSDN Forums. BTW, inheriting context from the ObjectContext does not work.

Are you still here? Well, my journey ended on last issue. I cannot live with it. This is enough for today. Tomorrow I will start with another approach. Hope my boss will not kill me for 6 wasted hours.