none
POCO Entity Generator RRS feed

  • Question

  • I created an app using EF 4.  In the following method, the following code works fine.  I then select Add Code Generation Item, using the EF 4.x POCO Entity Generator.  Running the same code throws the exception on ctx.GetObjectByKey.  Any ideas?

    Code:
    using (OrderItEntities ctx = new OrderItEntities())
    {
     var key = new EntityKey("OrderItEntities.Order", "OrderId", 11);
     var entity = ctx.GetObjectByKey(key);
    }

     

    Exception:

    Object mapping could not be found for Type with identity 'OrderItModel.Order'.


    Bill Behning

    Thursday, March 29, 2012 9:57 PM

Answers

  • Hi WRBehning,

    Welcome to MSDN Forum.

    Please check the key which you instantiated. EntityKey Class has three constructors, in your post, I think you are using "EntityKey(String,String,Object)". The first parameter is the entity set name qualified by the entity container name. The second parameter is the name of the key. The third parameter is the key value. Please refer to the document here. I think the entities' names which POCO Entity Generator generated may different with what you have used.

    Best Regards


    Allen Li [MSFT]
    MSDN Community Support | Feedback to us

    Monday, April 2, 2012 2:32 AM
    Moderator