Monday, January 28, 2013

OData And Entity Framework.

OData is probably one of the most powerful tools I've found.  It supports Interceptions, which means you can have authentication on any methods you need / want to lock down.

Most of Mobile development is making web service methods that allow you to Update / Create and Delete your Entities.  With OData.. most of that work can be quickly handled.

Frankly, getting it into use takes about 10 minutes, just to start working with it.  The needs of your project will determine how much additional work you need to do (Securing it, if it is a publicly exposed service, etc)  If you additionally install Entity Framework Power Tools, you get a whole lot of bang for your buck with an existing Database, with Code First.

I want to show you some urls, you can use, to see how powerful this tool is.

http://services.odata.org/website/odata.svc/ODataCustomers?$format=json
http://services.odata.org/OData/OData.svc/Products?$format=atom

Basically, on the fly, it will let me convert the Entity Objects, to Json format.. Atom, and XML (I believe these are the main formats that can be returned)

A great reference for using OData : http://www.odata.org/documentation/uri-conventions

If you go down this route, you might as well get a copy of LinqPad, it's a life saver.

LinqPad - The only way to fly with data and Linq.

Useful for getting the ODataService (Which allows $format=json in your OData Queries) if you are using an ASP.net Stack.

WCF Data Services ToolKit (Nuget)


A link for how to secure your OData Service with Custom Authentication.

Custom Authentication for OData.


LinqPad display of an OData Data Source.

Tuesday, January 22, 2013

Entity Framework.

Before I get going on heavy coding for the day, I wanted to post some comments on a debacle I had a bit ago.  I kept the link, and it was a really annoying situation.

I was wanting Code First Entity Framework to be implemented in my project, and for a bit, I worked on it manually.  Then I found some Nuget packages for Entity Framework that reverse engineer your dbcontext from an existing database.  I was in Visual Studio 2012, and I couldn't get the darn thing to work.  Kept telling me that it couldn't find T4VSHost, so I went on a google trip.   Found this link and the workaround.

Entity Framework Error.

I went to this location :

C:\Program Files (x86)\Microsoft Visual Studio 11.0\Common7\IDE\Extensions\Microsoft\Entity Framework Tools\Templates\Includes\EF.Utility.CS.ttinclude (for C#)

Deleted this line.

<#@ CleanupBehavior Processor="T4VSHost" CleanupAfterProcessingTemplate="true" #>

That was pretty much the end of my EntityFramework problems for what I was trying to get to happen.  Since then, I've been using AutoMapper, and the custom converters, or just selecting into new types with my lambda's.

AutoMapper Converters

Entity Framework allows a lot more flexibility than Linq to SQL, but it comes with additional overhead, and more "rules".   I love Code First, gives me a lot more control, without losing any of my customization.