I have these entities (this is just an abstraction I created for this post):
These are the references between them:
If I fetch like this:
var myFetch = from c in context.Districts
where c.Id = 10
select new { DistrictId = c.Id, Lang = c.Language };
and after that, I try to assign it to Description like this:
Description desc = Description.CreateDescription(0, "My description");
desc.DistrictReference.EntityKey = new EntityKey("MyEntities.Descriptions", "DistrictId", myFetch.DistrictId);
desc.Language = myFetch.Lang; //throws error
The error thrown is:
System.InvalidOperationException: The relationship cannot be defined because the EntitySet name 'MyEntities.Descriptions' is not valid for the role 'District' in association set name 'MyEntities.District_Description'.
What am I doing wrong?
if myFetch
were to be an instance of the class District
you could do it programmatically:
desc.DistrictReference.EntityKey = new EntityKey(
String.Format(
"{0}.{1}",
myFetch.EntityKey.EntityContainerName,
myFetch.EntityKey.EntitySetName),
"DistrictId",
myFetch.DistrictId);