views:

94

answers:

2

I have run into a problem which have searched and tried everything i can to find a solution but to no avail. I am using the same repository and context throughout the process

I have a booking entity and a userExtension Entity Below is my imagealt text

i then get my form collection back from my page and create a new booking

 public ActionResult Create(FormCollection collection)
    {
        Booking toBooking = new Booking();

i then do some validation and property assignment and find an associated BidInstance toBooking.BidInstance = bid;

i have checked and the bid is not null. finally i get the user extension file from the Current IPRINCIPAL USER as below

UserExtension loggedInUser = m_BookingRepository.GetBookingCurrentUser(User);
            toBooking.UserExtension = loggedInUser;

The Code to do the getUserExtension is :

 public UserExtension GetBookingCurrentUser(IPrincipal currentUser)
    {

        var user = (from u in Context.aspnet_Users
                             .Include("UserExtension")
                             where u.UserName == currentUser.Identity.Name
                             select u).FirstOrDefault();

        if (user != null)
        { 
            var userextension = (from u in Context.UserExtension.Include("aspnet_Users") where u.aspnet_Users.UserId == user.UserId select u).FirstOrDefault();
            return userextension;
        }
        else{
        return null;
        }
    }

It returns the userextension fine and assigns it fine. i originally used the aspnet_users but encountered this problem so tried to change it to the extension entity. as soon as i call the :

  Context.AddToBooking(booking);
        Context.SaveChanges();

i get the following exception and im completely baffled by how to fix it

Entities in 'FutureFlyersEntityModel.Booking' participate in the 'FK_Booking_UserExtension' relationship. 0 related 'UserExtension' were found. 1 'UserExtension' is expected.

then the final error that comes to the front end is:

Metadata information for the relationship 'FutureFlyersModel.FK_Booking_BidInstance' could not be retrieved. Make sure that the EdmRelationshipAttribute for the relationship has been defined in the assembly. Parameter name: relationshipName..

But both the related entities are set in the booking entity passed thruogh

PLEASE HELP Im at wits end with this

A: 

Sounds like a problem in your .Edmx file. Try recreating the edmx file from scratch and see if it solves the problem.

jfar
A: 

I found the problem. it turns out i was linking a Separate object to the users tableand it had a related entity as the booking table has a parent object so there was a mostly blank booking object through a couple of levels of entities that was trying to be added. this occurred as i didnt realise that if u link an entity to a new entity it automatically adds it to the context so this entity was missing . thanks all for the assistance

Barry