Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

EF4 is throwing an error "Schema specified is not valid"

I'm getting a weird EF4 "Entity Framework v4" error when I do a select on the context:

Schema specified is not valid. Errors: The relationship 'AnalyzerConfigurationModel.FK_AnalyzerMetadataParameters_AnalyzerMetadata' was not loaded because the type 'AnalyzerConfigurationModel.AnalyzerMetadataParameter' is not available.

The query to generate the error is:

Using context As New AnalyzerConfigurationEntities
      Dim EFAnalyzerConfiguration = (From P In context.AnalyzerConfigurations
                                     Where P.Name = analyzerConfigurationName).FirstOrDefault
End Using

The schema is show below. alt text

I've checked the connection strings, multiple times, its not that. Everything looks fine. I'm not sure if the XML that gets generated from this schema is off or not. But looked there too and don't see anything off or different from other properties. Has anyone run into this one before?

like image 353
irperez Avatar asked Jun 15 '10 15:06

irperez


3 Answers

I found that if I expanded the EDMX file in solution explorer (VS 2012) and right clicked on each .tt file and selected Run Custom Tool also fixed the issue. This might be easier than de

like image 150
CWaters Avatar answered Nov 11 '22 23:11

CWaters


Also make sure you're referencing project has the EntityFramework installed otherwise the dependent code will get this error.

https://www.nuget.org/packages/EntityFramework

like image 42
dynamiclynk Avatar answered Nov 11 '22 21:11

dynamiclynk


Let me explain this:

The problem is because the system did not find consistency of the columns in database, the entities in the .edmx file and the model class and also the use of the same in the controller class.

So follow the following steps to fix this up:

  1. Go to the database, check all the column names and properties.
  2. Confirm them with the class diagram in the.edmx file. Right-click on the class in which you are getting the error, and select update option for the class. Select the Refresh tab in dialogue (if there is no new column added. if new column is added, you can select the add tab.) and select the relevant objects. Generally they are tables. So select them and finish.
  3. Next check the names in the model class and the controller class.

This should be the solution. If not, let me know.

like image 1
Tushar Sharma Avatar answered Nov 11 '22 21:11

Tushar Sharma