Saturday, September 20, 2008

LINQ to SQL Expressions and WCF

I'm currently involved in an extensive migration of an existing .Net remoting architecture to WCF. The original architecture used Net Tiers in the data layer, which has been replaced by LINQ to SQL. We opted for LINQ to SQL over the Entity Framework, because EDM frankly offers little for a great deal of overhead additionally it just doesn't support functionality that it should.

One of the issues that we ran into during the migration was the migration of services methods that relied on client side criteria to filter the data, the original implementation used code that was heavily dependant on the Net Tiers metadata to write the queries on the client and pass them to the proxy. Initially  it looked as if Expression<Func<T,TResult>> would provide a perfect solution, it allowed us to create the expression and replace the current implementation with little impact. Unfortunately, it turns out that this solution won't work since Expressions can't be serialized. So we were left with the option of rolling a new dynamic query engine that could build the expression trees on the server, based on a string passed from the client. Initial discoveries lead us to believe it was feasible to create the expression in this way, but it would cost hours that we really didn't have.

  Then I ran across this article on ScottGu's blog regarding LINQ dynamic queries. After downloading the C# samples and looking at what it contained, it turned out that for the most part it contained most of the functionality we would need to create. So if you find yourself in need of the ability to pass queries across the wire to LINQ this is a great place to start.

Tuesday, September 9, 2008

Working around DataContract serialization with existing .Net classes

I'm working on moving some existing code to WCF. The code was originally passed via remoting so I thought it would be a pretty straight forward move. Turns out that's not the case. I ran into an issue with properties defined as System.Object and WCF. The error message that was returned was telling me that the connection was forcibly closed by the host, which I'm finding out can really be interpreted as "There was a problem with the object you want". After tracking the problem for the better part of the day it came down to an issue with the properties which looked like this:

[DataContract]
public class ContractTest
{
[DataMember]
public int PropOne { get; set; }

[DataMember]
public object PropTwo { get; set; }

[DataMember]
public string PropThree { get; set; }

[DataMember]
public object PropFour { get; set; }
}





It turns out that the serialization of the data contract can be altered by using the XmlSerializer. This is really helpful when moving older code. So to fix the issue, I modified the class like this:



using System.ServiceModel;

[DataContract]
[XmlSerializerFormat]
public class ContractTest
{
[DataMember]
public int PropOne { get; set; }


public object PropTwo { get; set; }

[DataMember]
public string PropThree { get; set; }


public object PropFour { get; set; }
}

The XmlSerializer will serialize the public properties and the end result is that you can now pass the class through the service noramlly.

Sunday, August 17, 2008

ADO.Net Entity Data Framework

I've spent a great deal of time with the Entity framework over the past month trying to incorporate into an application solution. I had high hopes that the framework, but after a month it's left me with a bad taste. No matter how you slice it, this framework is not ready for prime time. Here are a few issues that I have with it so far.

1. The Conceptual Data model does not allow me to abstract from the data store, I thought this was the great promise of this model but it turns out to be the great impendence mismatch magnifier. The mappings are absolutely unforgiving in complex situations. Mapping is really an all or nothing scenario, if every key isn't matched you'll never be able to map the entities.

2. The EDM modeler has a real difficult time with poorly normalized data stores. Arguably this could be addressed by cleaning and normalizing the database, however, it's currently not an option in this project and I'm sure that this is not an uncommon enterprise scenario.   As a result it is nearly impossible to map the entities in the store, even though it can be accomplished with LINQ2SQL.

3. I've run into issues where the model generator will, for whatever reason, just arbitrarily change the namespaces. and the fact that you can view the conceptual model at all is just unbelievable given that the conceptual model is such a central part in the framework.

4. Now I have to learn a number of new query technologies in order to use the model effectively. And coincidentally none of these models provides any real benefit when you need strong typing and generic runtime support.  

So if I had a chance to start over, LIN2SQL would be my first choice, especially given the the DB lives on SQL Server. The LINQ2SQL programming and mapping models are more forgiving and easier to work with as well as being functional.  If these issues and the multitude of other issues addressed in other blogs and numerous forums aren't addressed, the Entity framework will be stillborn. My advise to anyone who is considering LINQ2SQL and EDM for a SQL server based project would be this, save yourself pain, time and productivity and go with LINQ2SQL.

Tuesday, August 12, 2008

In case you've been in a cellar (VS2008 SP1)

 

  Visual Studio 2008 SP1 and .Net 3.5 SP1 have been released, you can download them from the links below as well as a the service pack prep utility.

Visual Studio 2008 SP1 and .Net 3.5 SP1 download

Service Pack Preparation Utility

My installation on two machines went without a hitch. I completely uninstalled SQL server and Visual Studio , deleted the remaining directories and defragged before reinstalling. I installed in the following order on both machines.

  1. SQL Server 2008 Developer
  2. Visual Studio 2008
  3. Visual Studio 2008 SP1

SQL server will install the .Net 3.5 service pack. 

So far everything runs fine, one disappointment thought was the missing WPF controls promised during the beta. The Office ribbon bar is nowhere to be found but the new grid control is available separately on Codeplex  as part of the WPF Toolkit.

Wednesday, August 6, 2008

Vs 2008 SP1

I posted earlier that SQL 2008 RTM is available to MSDN and Tech Net subscribers which is great, but it appears the Visual Studio 2008 SP 1 will not be available for download until the 11th of August.  These timing issues are annoying to say the least. Both of these pieces are needed in a development environment, in fact without SP1, you can't program against SQL 2008. Let's hope that they release prior to the 11th, but if not at least we have a known date.

SQL 2008 has been released to manufacturing

SQL Server 2008 has been released to manufacturing (RTM). I posted earlier that I thought it would happen by the end of this month, so I was pretty close. It's already available for MSDN and Tech Net subscribers.  Now how about the VS 2008 SP1 RTM?

Saturday, August 2, 2008

Visual Studio 2008 SP1 and SQL 2008 close to release?

Just ran across a set of slides for the Visual Studio 2008 SP1 launch here. So is it possible that we may finally see RTM of the Service Pack and SQL 2008 in the next couple of weeks? I suspect that it may be pretty close, maybe by the end of August. This would be great because we've been using the beta and SQL 2008 RC internally to ramp up vNext of our application.