This question is locked. New answers and comments are not allowed.
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:
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:
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:
Any help greatly appreciated
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:
- OpenAccess is getting confused as the Project class is derived from Group (using flat hierarchy)
- 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