Framework Madness!

And other adventures C# and …

Archive for March 2009

Entity Framework vNext to Support Self Tracking Entities

leave a comment »

Other questions on shared libraries and use with “POCO” remain unanswered.


Written by Lynn Eriksen

March 24, 2009 at 7:08 pm

Posted in Uncategorized

Ado.Net Data Services – Are you experienced?

with one comment

I am in the process of deploying my first project using Data Services using an Entity Framework Context and I thought I would share some of my experience.

1) Authentication

Data services comes with the ability to apply credentials on the context, but if you’re wanting to roll-your-own method of passing credentials (such as a cookie) you’re not out of luck. The client ObjectContext supports a “SendingRequest” that is fired every time an HttpWebRequest object is created. In the args object you can get access to the web request. The code looks something like this:

private static void Context_SendingRequest(object sender, SendingRequestEventArgs e)
   if (e != null && (e.Request as HttpWebRequest != null))
       var Request = e.Request as HttpWebRequest;
       Request.CookieContainer = new CookieContainer();
       Request.CookieContainer.Add(new Cookie("token", "value") { Domain = Request.RequestUri.Host });

You can then use the cookie you in the service by overriding the “OnStartProcessingRequest” method.

   1: protected override void OnStartProcessingRequest(ProcessRequestArgs args)
   2: {
   3:         try
   4:         {
   5:             var Cookie = HttpContext.Current.Request.Cookies["token"];
   7:             var Ticket = FormsAuthentication.Decrypt(Cookie.Value);
   9:             if (Ticket != null && Ticket.Expired)
  10:             {
  11:                 throw new DataServiceException("");
  12:             }
  15:         }
  16:         catch (Exception)
  17:         {
  19:             throw new DataServiceException("Invalid Login");
  20:         }
  22:     base.OnStartProcessingRequest(args);
  23: }

2) .SVC mapping in IIS

For the .svc mime type mapping in IIS you’ll need to make sure the “POST”, “PUT’” and “DELETE” methods are supported.


3) Object Context  and connection string

After having trouble creating an object context using an .edmx file directly in an web site I moved it do a class library and everything seems fine now. Also, it’s very important to make sure your connection string is formatted correctly. When you create and ObjectContext using .edmx it will create a connection string in the .config file that corresponds to the class name of the object context. Additionally, it is very important  the connection string “metadata” section be formatted as “metadata=res://*/Context.csdl|res://*/Context.ssdl|res://*/Context.msl;”. And this is where it gets to be interesting. When you create the .edmx file a custom Object Context is created, but also portions of the .edmx file are embedded as resources in the compiled assembly. The “res://*/” paths, which are pipe separated (“|”), need to correspond to these resource names in the compiled assembly. If you don’t don’t know the names you can always use RedGate Reflector to find them. Thanks to Danny Simmons at Microsoft for pointing the right me in the right direction.


4) Turn on debugging output if needed.

There are two things you can do to get at error messages in the service output if necessary.

  1. Apply the ServiceBehavior attribute to the service. When you do this you want to include (“IncludeExceptionDetailInFaults = true”).
  2. In the “InitalizeService” method include “config.UseVerboseErrors = true”.

This will allow you to get at the exception details. Make sure you turn off when in production.

Written by Lynn Eriksen

March 24, 2009 at 10:36 am

Expression Web Super Preview – Beta

with 3 comments

Super Preview showing IE7 and IE 6 side-by-side.Yesterday at Mix 09 the Expression Web team put out a public demo of something they call Super Preview. Essentially this allows you to preview initial browser page output over multiple IE versions. I  installed IE 8 today, and I can preview IE 8, IE 7 ( in IE 8’s IE7 emulation mode), and IE 6 which I thinks renders using a cloud service. Here’s the link:

Works great. It even renders the IE8.js corrections applied.


Note: The final version that ships in Expression Web 3 will support FIreFox and other browsers. I am wondering if they will maintain Super Preview as a free download after EW 3 ships and if so with what features supported.

Written by Lynn Eriksen

March 19, 2009 at 2:03 pm

Posted in Uncategorized

Tagged with ,

Resharper 4.5 – First Impression

leave a comment »

I took a bite on Resharper 4.5 on my home machine. My first impression is positive. Two big things I noticed:

  1. As advertised – Reshaper is MUCH faster. My home machine in a Dell Inspiron 9300 laptop with Pentium M @ 1.73 Ghz running the Windows 7 beta. Perceived  drag on small and large solutions is much lower. VS 2008 just seems much more responsive with 4.5 beta.
  2. In C# renaming a folder will refactor the namespace for contained files. Very nice. Don’t know if 4.1 has that.    

Written by Lynn Eriksen

March 18, 2009 at 9:55 am

Posted in Uncategorized

Tagged with

XElement and XPath: Covalent Bonding

leave a comment »

Yes. It’s true. You can use XElement and XPath together.

I was working on an applet today using XElement and was having a hard time getting at nested elements. I kept searching the XElement members in VS intellisense but couldn’t get anything that even hinted at XPath like support. Well a trip to the XElement members documentation enlightened me. ( It looks like if you import the System.Xml.XPath name space you get full XPath support for returning single or multiple XElement vis-à-vis extension methods. That makes things SO much easier working with XElements. Saved a TON of time!

Written by Lynn Eriksen

March 7, 2009 at 2:48 am

Posted in Uncategorized

Tagged with Data Services v 1.5 – Help is on the way!

leave a comment »

Okay – corny title. Sorry. But after my initial elation in working with Data Services I ran into a couple of “issue” and this news helps keep me going. Such as not being able to get a virtual count being the most outstanding problem. Here’s that link:

Looks like it will be a side-by-side release. Now that could be good or very good. Hint – if we have to give up the VS 2008 tooling it’s only “good”.

I’m very pleased that they are responding sooner that forcing a longer wait until .Net 4/VS 2010. I still very much dislike the Entity Framework v1 design choices (specifically the forced reliance on an xml mapping schema), but the pain is worth the gain. The book “Programming Entity Framework” is a big help.

Written by Lynn Eriksen

March 4, 2009 at 6:10 pm

Posted in Uncategorized

Tagged with ,