Deal of the Day

Home » Main » Manning Forums » 2009 » Entity Framework 4 in Action

Thread: If you are having problems

Reply to this Thread Reply to this Thread Search Forum Search Forum Back to Thread List Back to Thread List

Permlink Replies: 2 - Pages: 1 - Last Post: Jul 22, 2011 1:36 PM by: JustMe2
JustMe2

Posts: 25
From: Los Gatos, CA
Registered: 6/28/11
If you are having problems
Posted: Jul 14, 2011 5:14 PM
  Click to reply to this thread Reply

Hi all,

I am working my way through the book and am encountering problems. As I figure out the answers, I will post them to this thread. If you have already found some and know the answers, feel free to add them to this thread.

The following were tested with EF4.0 and EF4.1

If you get the error:
"The specified named connection is either not found in the configuration, not intended to be used with the EntityClient provider, or not valid." and it's on a line that ends with ": base(ConnectionString, ContainerName)" you need to add an "Application Configuration File" to your UI project. Just use the default "App.config" name. Then go to the Model project and open that projects App.config file. You should see a connection - copy the connection (with beginning/ending tags) and put it into the app.config you just added to your GUI project.

This should fix the problem.

Also, if you are getting any one of a number of weird errors when playing with files you copied from the source, check if you are calling the dump() method. If so, it has a bug. The EF works fine, but the dump() does not. The most common message you might see is:
"Exception: System.reflection.targetInvoationException: ..... " and it might include a line that says "The connection is not open." This is from the dump command.
Of course, when the dump command works, it displays a nice rendering of the Entity, but until we have a fix.....

More to come as I work through the book....

JustMe2

Posts: 25
From: Los Gatos, CA
Registered: 6/28/11
Re: If you are having problems
Posted: Jul 22, 2011 1:30 PM   in response to: JustMe2 in response to: JustMe2
  Click to reply to this thread Reply

On page 76, in the example at the top, the code reads:
var result = ctx.Order.Where(o => o.Date.Year == DateTime.Now.Year);

In my case, there was no field named Date, so I got a weird error. Try using intellisence to identify the correct field. In my case, the following worked:

var result = ctx.Order.Where(o => o.OrderDate.Year == DateTime.Now.Year);

I point this out as the error message doesn't really indicate what is wrong with the statement. So now you know...

JustMe2

JustMe2

Posts: 25
From: Los Gatos, CA
Registered: 6/28/11
Re: If you are having problems
Posted: Jul 22, 2011 1:36 PM   in response to: JustMe2 in response to: JustMe2
  Click to reply to this thread Reply

In regards to the prior post, you must also have the following using statement in order for the next line to work:

using System.Data.Objects;

JustMe2

Legend
Gold: 300 + pts
Silver: 100 - 299 pts
Bronze: 25 - 99 pts
Manning Author
Manning Staff
Manning Developmental Editor