Entity Framework and Entity LINQ : First Thoughts

Recently over the last week I have had some time to get Visual Studio Service Pack 1 installed on my machine and a chance to play with the Entity Framework and Linq to Entities.  I had very high hopes for the Entity framework.  The ability to create custom mappings that could even span multiple database has the potential to make many of the difficulties that are faced when designing data oriented system obsolete. In addition, combined with the set manipulation powers of Linq we would be able to write cleaner more compact code that would still give us enough control to make the SQL as efficient as needed for the project at hand.

Sadly, Microsoft has seemingly not delivered on all of these promises for the first version.  While I had no false aspirations that the support for spanning multiple database’s with associations would be in place, I had thought that the basic mapping support would be in place.  For example, if I have two Entities (Series and Studio) which are related via the foreign key relationship, that One Studio has Many Series, one would think that if I wanted to create a new Entity VerboseSeries which contained only the information that I needed (SeriesName and StudioName) you would easily be able to.

However, after going around in circles for hours and reading as much as I can from the limited amount of information available from Microsoft I have not been able to find anything above the basics of using the wizard to automatically create the models.  Hence, I am forced to rely on the old means of adding custom properties to the objects represented by the modals: partial classes.

The other thing that I have noticed is that to the uninitiated the Linq to Entity side of things is not quite as clear as it should be.  For example, give the scenario I described above with the two Entities (Series and Studio) one may be inclined to use Linq code from DLinq as shown below to retrieve the data:

var series = from s in dc.Series
             where s.StudioId == studioId
             select s;
However, with the EDM model it would look like this:
var series = from s in em.Series
             where s.Studio.StudioId == studioId
             select s;

Not as straight forward as the DLinq version in my book, though they both generate identical SQL with the minor difference being the join type (Entity uses a LEFT join and DLinq uses an Inner join).  I will leave it to the SQL community to decide which is the more efficient means of obtaining correlated information.  The upside to this is that from the basic example I created it would appear that Linq to Entity query generation is more efficient then Linq to SQL.

Based on this information, I am still optimistic about the Entity Framework, though I am disappointed that it is so difficult to do even basic mapping.  I continue to have high hopes for the framework, though I certainly will not be recommending it over our framework anytime soon.  To help spread the knowledge I am including links to all the pages with information on the Entity Framework and Linq to Entities:

I am hoping that I am merely doing something incorrectly which is causing me the level of difficulty I am experiencing with the mapper.

 

.csharpcode, .csharpcode pre
{
font-size: small;
color: black;
font-family: consolas, “Courier New”, courier, monospace;
background-color: #ffffff;
/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt
{
background-color: #f4f4f4;
width: 100%;
margin: 0em;
}
.csharpcode .lnum { color: #606060; }

.csharpcode, .csharpcode pre
{
font-size: small;
color: black;
font-family: consolas, “Courier New”, courier, monospace;
background-color: #ffffff;
/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt
{
background-color: #f4f4f4;
width: 100%;
margin: 0em;
}
.csharpcode .lnum { color: #606060; }

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s