Saturday, April 23, 2011

Entity Framework Error - The relationship '{0}' was not loaded because the type '{1}' is not available.

I had changed an applications data architecture slightly and instead of going to a network Sql Server instance, I decided to use the App_Data folder to make this application distribute a bit easier for demo purposes.

This error was caused because my connect string wasn't correct to the database. The connect strings for App_Data databases use a local path to attach to a database file such as:
AttachDbFilename=|DataDirectory|\MyDatabase.mdb

I thought my connect string was correct in the web.config of the application that used my data access layer and the error doesn't of course tell me anything is wrong with my connect string, but I figured I'd give it a try.

In order to properly reference my database in _another project_ I needed the dialog to give me the connect string to make sure it was all 100% ok, and then I just would edit the db path to be relative from the absolute path the dialog displays. So - I went back into my data access project and selected to add a new entity framework model. When the dialog came up, I simply copied the app_data database connectstring and then canceled out of the dialog and updated my other project's web.config:





Schema specified is not valid. Errors:
The relationship 'NASA.FK_Booster_Catalog' was not loaded because the type 'NASA.Catalog' is not available.
Exception Details: System.Data.MetadataException: Schema specified is not valid. Errors:
The following information may be useful in resolving the previous error:
The required property 'Password' does not exist on the type 'NASA.DataAccess.Models.Catalog'.

Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

The required property 'Password' does not exist on the type 'WebStore.DataAccess.Models.Customer'.



Source Error:

Line 69: public ObjectSet Products
Line 70: {
Line 71: get { return _catalogs ?? (_catalogs = CreateObjectSet("Catalogs")); }
Line 72: }
Line 73: private ObjectSet _catalogs;

Stack Trace:

System.Data.Metadata.Edm.ObjectItemCollection.LoadAssemblyFromCache(ObjectItemCollection objectItemCollection, Assembly assembly, Boolean loadReferencedAssemblies, EdmItemCollection edmItemCollection, Action`1 logLoadMessage) +480
System.Data.Metadata.Edm.ObjectItemCollection.ImplicitLoadAssemblyForType(Type type, EdmItemCollection edmItemCollection) +84
System.Data.Metadata.Edm.MetadataWorkspace.ImplicitLoadAssemblyForType(Type type, Assembly callingAssembly) +151
System.Data.Objects.ObjectContext.GetTypeUsage(Type entityCLRType) +35
System.Data.Objects.ObjectContext.GetEntitySetForNameAndType(String entitySetName, Type entityCLRType, String exceptionParameterName) +33
System.Data.Objects.ObjectContext.CreateObjectSet(String entitySetName) +66
..
..
..

No comments:

Post a Comment

Note: Only a member of this blog may post a comment.