I'm working with dotConnect 7 (last version downloaded last week).
I have this two model classes:
Code: Select all
public class User
{
public User()
{
Settings = new List<UserSettings>();
}
public int Id { get; set; }
public string Name { get; set; }
public ICollection<UserSettings> Settings { get; set; }
}
public class UserSettings
{
public int Id { get; set; }
... (other properties)
public int UserId { get; set; }
public User User { get; set; }
}
Working with DTO let me insert a new record on the UserSettings table when I know only the "Id" of the user.
But, if I use the convention (User property has UserId foreign key, as Microsoft explain), when I try to read data from the DB, it says that "UserId" column is not found.
If I take off the "UserId" property (as seen in devart example), how can I do the same insert but without read the "User" record?
I'd like to write something like that:
Code: Select all
UserSettings us = new UserSettings();
// I know there is a user with Id 1, but I won't read it from the DB
us.UserId = 1;
....
DbContext.Set<UserSettings>().Add(us);
DbContext.SaveChanges();
Can you tell me how to do?
Thank you in advance