я пытаюсь сделать приложение и получил небольшую проблему. моя структура выглядит следующим образом:
public class BaseModel
{
[Key]
private int _Id;
public int Id {
get { return _Id; }
set { _Id = value; }
}
}
public class SupplierModel : BaseModel
{
[ForeginKey("CountryCode")] // This should map to say "se" or "no" or whatever in the CountryModel table
public virtual CountryModel Country;
}
public class CountryModel : BaseModel
{
private string _CountryCode;
[Key] // This should be another key in the table to get the actual country.
public string CountryCode {
get { return _CountryCode; }
set { _CountryCode = value; }
}
private string _CountryName;
public string CountryName {
get { return _CountryName; }
set { _CountryName = value; }
}
}
Теперь я хочу, чтобы SupplierModel связывался с CountryModel (отлично работает по Id), но я хочу, чтобы это был код страны, который будет отношением, а не Id между сущностями.
Таким образом, доступ к CountryModel.Country должен сопоставиться с таблицей CountryModel и извлечь ту, которая соответствует модели страны.
Надеюсь, я не испортил вам все, трудно объяснить, когда я это сделаю не полностью понимаю структуру сущности и отношения с базой данных .. пытаюсь научиться =)