S
shapper
Hello,
I am creating a User with Linq To SQL.
Each user is associated with a District and to one or more Levels in
Many to Many relationship through UserLevel.
I tried the following:
_user.District = new Entities.District { Id = user.District.Id };
IEnumerable<Entities.UserLevel> levels = user.Levels.Select(l => new
Entities.UserLevel { LevelId = l.Id });
_user.UserLevels.AddRange(levels);
I get the error:
Cannot insert the value NULL into column 'Name', table
'DB.dbo.Districts'; column does not allow nulls. INSERT fails.
The statement has been terminated.
I think I will have the same problem with Levels.
Both District and Level has two properties: Id (PK) and Name.
So basically I think I need to create some kind of Join or get the
District and Levels with the given Id's before I add them to the user.
Anyway, how can I do this?
Thank You,
Miguel
I am creating a User with Linq To SQL.
Each user is associated with a District and to one or more Levels in
Many to Many relationship through UserLevel.
I tried the following:
_user.District = new Entities.District { Id = user.District.Id };
IEnumerable<Entities.UserLevel> levels = user.Levels.Select(l => new
Entities.UserLevel { LevelId = l.Id });
_user.UserLevels.AddRange(levels);
I get the error:
Cannot insert the value NULL into column 'Name', table
'DB.dbo.Districts'; column does not allow nulls. INSERT fails.
The statement has been terminated.
I think I will have the same problem with Levels.
Both District and Level has two properties: Id (PK) and Name.
So basically I think I need to create some kind of Join or get the
District and Levels with the given Id's before I add them to the user.
Anyway, how can I do this?
Thank You,
Miguel