Weird ADO.NET Entity Framework behaviour

by Pascal Parent 17. April 2009 13:53

I started my project using a Microsoft SQL 2008 server and the ADO.NET Entity Framework only to find out that the host does not support Microsoft SQL 2008 server but only supports Microsoft SQL 2005 server.

Generally, I would just port the database and change the connection string… Which is what I did!

EF was not happy about that because EF still thought it was a SQL 2008 server and built it’s T-SQL accordingly, which failed because it used new commands. This was fine with me, until I realised to my surprise that I could not find any settings to change EF’s SQL version, I searched the code, the config files,...

A Google search did not return any valuable information either.

Though I found a solution, whether or not it is the best. Refresh the mapping file, rebuild the project and voila everything works again.

I find it odd though, I wander what would happen if I had switched to MySQL or Oracle.

Digg It!DZone It!StumbleUponTechnoratiRedditDel.icio.usNewsVineFurlBlinkList

Tags: , ,

ASP.NET | Database

Linq limitations

by Pascal Parent 12. April 2009 18:46

I am currently writing a small website for one of my companies clients and decided that I should use LINQ-to-Entities and the ADO.NET Entities Framework to make my life easier and to learn a bit more about LINQ. You may recall a statement I did a few months ago on Twitter “ADO.NET Entity Framework sucks! Linq Rocks!” well I stand by that but it has some serious shortcomings, I would call it a bug but then it would be a documented bug. You cannot use any Entity.Field.ToString in a Linq block!

So the following code will fail:

using (Entities db = new Entities())
{
    var news = (
                   (
                       from N in db.NewsSet
                       where N.PublishedDate <= DateTime.Now
                       orderby N.PublishedDate descending
                       select new
                       {
                           Date = N.PublishedDate.ToString("dddd, dd MMMM yyyy"),
                           Headline = N.Headline,
                           Article = N.Content,
                           Author = N.Author,
                       })
                   ).First();

    this.litHeadline.Text = news.Headline.Trim();
    this.lblDate.Text = news.Date.Trim();
    this.litArticle.Text = news.Article.Trim();

}

The error is: System.NotSupportedException: LINQ to Entities does not recognize the method 'System.String ToString(System.String)' method, and this method cannot be translated into a store expression.

The line that will fail is Date = N.PublishedDate.ToString("dddd, dd MMMM yyyy") because I use ToString, which in my opinion is ridiculous. Why can I not format or manipulate the variable as I wish? Microsoft, please fix this or remove the Intellisence that allows me to do that. See be llow.

Linq.ToString

The actual code that works is here bellow:

using (Entities db = new Entities())
{
    var news = (
                   (
                       from N in db.NewsSet
                       where N.PublishedDate <= DateTime.Now
                       orderby N.PublishedDate descending
                       select new
                       {
                           Date = N.PublishedDate,
                           Headline = N.Headline,
                           Article = N.Content,
                           Author = N.Author,
                       })
                   ).First();

    this.litHeadline.Text = news.Headline.Trim();
    this.lblDate.Text = news.Date.ToString("dddd, dd MMMM yyyy");
    this.litArticle.Text = news.Article.Trim();

}

For more information Muhammad Mosa has a good article called Linq to Entities, what is not supported? I highly recommend that you read it along with Microsoft’s MSDN Supported and Unsupported Methods (Linq to Entities) 

Next Dynamic Linq…

Digg It!DZone It!StumbleUponTechnoratiRedditDel.icio.usNewsVineFurlBlinkList

Tags:

General

The ASP.NET Guy goes live

by Pascal Parent 3. April 2009 14:40

It’s official my new ASP.NET and .NET site is live at http://www.theaspnetguy.com and it was not an easy task.

I had to export the entries from Wordpress, clean the data, import it into BlogEngine.NET clean the entries and voila a bran new blog! And a lot of work to come. And finally, I removed all development entries from Only in South Africa.

I needed it up because I am busy on an ASP.NET 3.5 SP1 project which will make extensive use of the dreaded ADO.NET Entity Framework and the lovable Linq to Entities.

Long live The ASP.NET Guy!

Cross posted from my personal blog Only in South Africa

Digg It!DZone It!StumbleUponTechnoratiRedditDel.icio.usNewsVineFurlBlinkList

Tags:

General

Welcome to BlogEngine.NET 1.5.0

by Pascal Parent 2. April 2009 09:00

If you see this post it means that BlogEngine.NET 1.5.0 is running and the hard part of creating your own blog is done. There is only a few things left to do.

Write Permissions

To be able to log in to the blog and writing posts, you need to enable write permissions on the App_Data folder. If you’re blog is hosted at a hosting provider, you can either log into your account’s admin page or call the support. You need write permissions on the App_Data folder because all posts, comments, and blog attachments are saved as XML files and placed in the App_Data folder. 

If you wish to use a database to to store your blog data, we still encourage you to enable this write access for an images you may wish to store for your blog posts.  If you are interested in using Microsoft SQL Server, MySQL, VistaDB, or other databases, please see the BlogEngine wiki to get started.

Security

When you've got write permissions to the App_Data folder, you need to change the username and password. Find the sign-in link located either at the bottom or top of the page depending on your current theme and click it. Now enter "admin" in both the username and password fields and click the button. You will now see an admin menu appear. It has a link to the "Users" admin page. From there you can change the username and password.  Passwords are hashed by default so if you lose your password, please see the BlogEngine wiki for information on recovery.

Configuration and Profile

Now that you have your blog secured, take a look through the settings and give your new blog a title.  BlogEngine.NET 1.4 is set up to take full advantage of of many semantic formats and technologies such as FOAF, SIOC and APML. It means that the content stored in your BlogEngine.NET installation will be fully portable and auto-discoverable.  Be sure to fill in your author profile to take better advantage of this.

Themes and Widgets

One last thing to consider is customizing the look of your blog.  We have a few themes available right out of the box including two fully setup to use our new widget framework.  The widget framework allows drop and drag placement on your side bar as well as editing and configuration right in the widget while you are logged in.  Be sure to check out our home page for more theme choices and downloadable widgets to add to your blog.

On the web

You can find BlogEngine.NET on the official website. Here you'll find tutorials, documentation, tips and tricks and much more. The ongoing development of BlogEngine.NET can be followed at CodePlex where the daily builds will be published for anyone to download.

Good luck and happy writing.

The BlogEngine.NET team

Digg It!DZone It!StumbleUponTechnoratiRedditDel.icio.usNewsVineFurlBlinkList

Tags: ,

BlogEngine.NET

Disclaimer
The opinions expressed herein are my own personal opinions and do not represent my employer's view in anyway.

© Copyright 2010 The ASP.NET Guy