views:

186

answers:

1

Hi

I just got this book

In it there is a .dll for a generic repository. I followed what he did but I always get a error.

System.InvalidOperationException was caught
  Message="The EntitySet name 'MyEntities.CarSet' could not be found."
  Source="System.Data.Entity"
  StackTrace:
       at System.Data.Objects.ObjectContext.GetEntitySet(String entitySetName, String entityContainerName)
       at System.Data.Objects.ObjectContext.GetEntitySetFromName(String entitySetName)
       at System.Data.Objects.ObjectContext.AddObject(String entitySetName, Object entity)
       at GenericRepository.EFGenericRepository.Create[T](T entityToCreate)
       at CarSite.com.Controllers.RController.Institutions(FormCollection regForm) in I:\p\trunk\Current Site\Controllers\RController.cs:line 227
  InnerException:

I have no idea why I am getting this. I can't see into the .dll so I don't know what is going on there.

My other repositories I wrote work fine. It's just his generic repository.

I think I have everything he has expect he has a typed view and the database stuff he needs comes through the parameter as a class.

Mine is in a form that I make like this

 Car send = new Car();
  send.Name= regForm["Name"];
  send.CarID=  regForm["ID"];

Authenticate.repository.Create<Car>(send);

I just can't see this effecting it?

Edit

Now I get this error

Entities in 'Entities.CarSet' participate in the 'FK_Car_aspnet_Users' relationship. 0 related 'aspnet_Users' were found. 1 'aspnet_Users' is expected.

I don't know how to add to my Create statement that passes int he values needed to satisfy this relationship.

A: 

The method EFGenericRepository.Create is somehow guessing that the entity set for the Car entity is called "CarSet". But it clearly isn't. So you can look at the codee for that method to see where the entity set name is coming from or change the name of the entity set for Car in the entity model.

Craig Stuntz
what method? The ones in the GenericRepository? Or my code?
chobo2
Again, look at EFGenericRepository.Create.
Craig Stuntz
Hi Ok I figured that out now I get a new error and not sure how to fix.See original post.
chobo2
Your "Car" entity has a non-nullable relationship to the ASP.NET Users table, but you haven't specified a user before saving.
Craig Stuntz
Sorry I don't follow what you mean. I am trying to add the stuff the fields as a relationship. I tried first doing a create and made the uesr then after create the Car stuff. Got that error. So my thinking now is I have to add the fields of the user and the fields of the car in one go.
chobo2
Your car has a **required** user field which you cannot leave null when you save the new car.
Craig Stuntz