Powered by MSDN

US - English
NEW! Silverlight 5 is available Learn More

Entities and Composition - "An EntityKey value cannot b... RSS

23 replies

Last post Mar 23, 2011 03:57 PM by sethd

(0)
  • silverlight_developer

    silverlight_...

    Member

    13 Points

    74 Posts

    Re: Re: Re: Entities and Composition - "An EntityKey value cannot be null" during delete (serious...

    Jun 06, 2010 02:02 AM | LINK

    Hello

    I have tried fixing the problem in OnCreated function in codegen but everytime i try to run it , it creates a new copy and changes made are lost. Where excatly I am supposed to do this :

     I get error in line :

    public override object GetIdentity()

    {

    return EntityKey.Create(this._driverName, this._driverVersion, this._name, this._standardVersion);

    }

    where in some cases this._driverVersion and  this._standardVersion

    can be null... It is an important concept as I have to write many queries where I will be joining multiple tables and some values can be null ... Please tell me how to fix this ?

     

    Thanks

  • mathewc

    mathewc

    Participant

    1030 Points

    184 Posts

    Microsoft

    Re: Re: Re: Entities and Composition - "An EntityKey value cannot be null" during delete (serious...

    Jun 07, 2010 05:11 PM | LINK

    You shouldn't implement OnCreated in the codegened file, you need to do it as a partial method in another file so it isn't overwritten.

    -Mathew [MSFT]
  • ingo.rammer

    ingo.rammer

    Member

    2 Points

    1 Post

    Re: Re: Re: Entities and Composition - "An EntityKey value cannot be null" during delete (serious...

    Jun 10, 2010 01:59 PM | LINK

     If anyone is interested, I've just posted a CodeProcessor which prepends the necessary nullness check to GetIdentity() to my blog.

    Cheers,
    -Ingo

  • sethd

    sethd

    Member

    4 Points

    2 Posts

    Re: Re: Re: Re: Entities and Composition - "An EntityKey value cannot be null" during delete (ser...

    Mar 23, 2011 03:57 PM | LINK

    I experienced this issue also. I tried to get Ingo's CodeProcessor to work but ran into some other issues with that.

    My entity has a composite key of type int and string.  What I did as a workaround was just change my int to a nullable int. Aparently the generated code works correctly when there are more than one nullable types in the key.


    It's not pretty, but it works. Granted, this means that my model does not truly represent the relationship correctly, but the value never ends up actually being null, so it does not cause any problems.