Skip Navigation LinksHome / Community & Support / Developer Productivity Tools Forums / OpenAccess ORM > General Discussions > Set Foreign Key Value

Not answered Set Foreign Key Value

Feed from this thread
  • Grant Drury-Green avatar

    Posted on Feb 6, 2012 (permalink)

    Hi,

    I'm working with an database first object model - and I'm facing an issue which I can only assume is something strange with my set-up.

    Basically, I'm trying to add a new object to the database - the table for which has some foreign keys like thus:

    public class Project : Group
    {
         public int CreatedByUserId {get; set;}
         public User CreatedByUser {get; set;}
      
         public string CountryCode {get; set;}
         public Country Country {get; set;}

          // more properties...
    }

    Rather than getting an instance of the User and the Country from the database, I'm setting just the CreatedByUserId and CountryCode properties (I know what these values are)

    Unfortunately, when I set just the value properties - I get an error:

    Insert of '235936052-' failed: Telerik.OpenAccess.RT.sql.SQLException:
    Cannot insert the value NULL into column
    'CountryCode', table 'Alumni.dbo.Group';
    column does not allow nulls. INSERT fails.
    The statement has been terminated.

    CountryCode has definitely been populated. Also, if I change the code to set just the Country and CreatedByUser properties - all is good...

    There's two possible things I can think of:
    1. OpenAccess is getting confused as the Project class is derived from Group (using flat hierarchy)
    2. OpenAccess doesn't support simply setting the foreign key value (I'm hoping this isn't the case - as I REALLY don't want to have to re-retrieve the user each time I create an object!)

    Any help greatly appreciated

    Reply

  • Petar Petar admin's avatar

    Posted on Feb 9, 2012 (permalink)

    Hi Grant Drury-Green,

     Can you please share with us the mapping of the association that is failing for you. To obtain the mapping you will need to open your rlinq file with an XML editor and look for the association in question.
    We are looking forward to your reply.

    Greetings,
    Petar
    the Telerik team
    Sharpen your .NET Ninja skills! Attend Q1 webinar week and get a chance to win a license! Book your seat now >>

    Reply

Back to Top

Skip Navigation LinksHome / Community & Support / Developer Productivity Tools Forums / OpenAccess ORM > General Discussions > Set Foreign Key Value
Related resources for "Set Foreign Key Value"

OpenAccess ORM Features  |  Documentation  |  Demos  |  Telerik TV  |  Step-by-step Tutorial   ]