This question is locked. New answers and comments are not allowed.
Hello
I'm having some problems with my associations based on NOT NULL foreign keys.
I am using a "Database First" model and i have put together a simple example with 2 entities.
ORDER has a foreign key to CUSTOMER which is not null
Is this the expected behavior?
Best regards Fredrik
I'm having some problems with my associations based on NOT NULL foreign keys.
I am using a "Database First" model and i have put together a simple example with 2 entities.
ORDER has a foreign key to CUSTOMER which is not null
Is this the expected behavior?
////////////////////////////////////////////////////////////////////////////////////////////////
//This works fine
using
(EntitiesModel1 context =
new
EntitiesModel1())
{
var aCustomer = context.CUSTOMERs.Where(c => c.CustomerNumber ==
"1000"
).First();
var anOrder =
new
ORDER();
anOrder.CUSTOMER = aCustomer;
anOrder.OrderNumber =
"Ordernumber 1000"
;
context.Add(anOrder);
context.SaveChanges();
}
////////////////////////////////////////////////////////////////////////////////////////////////
//This throws a Telerik.OpenAccess.Exceptions.NoSuchObjectException
//Message=No row for WpfApplication12.CUSTOMER ('CUSTOMER') GenericOID@a6a45507 CUSTOMER Id=0
using
(EntitiesModel1 context =
new
EntitiesModel1())
{
var aCustomer = context.CUSTOMERs.Where(c=>c.CustomerNumber ==
"1000"
).First();
var anOrder =
new
ORDER();
context.Add(anOrder);
anOrder.CUSTOMER = aCustomer;
//Throws exception
anOrder.OrderNumber =
"Ordernumber 1000"
;
context.SaveChanges();
}
Best regards Fredrik