Данные не читаются из таблицы с использованием Entity Frame Work
Я использую Entity Framework 6.2 код первый подход. Я создал эти 3 класса
Первый класс:
[Table("UserAccount")]
public class UserAccount
{
[Key()]
[ForeignKey("Employee")]
public Guid UserAccountId { get; set; }
[MaxLength(255)]
public string UserName { get; set; }
[MaxLength(255)]
public string Password { get; set; }
private UserPermissions _UserPermissions = new UserPermissions();
[Required]
public UserPermissions UserPermissions { get { return _UserPermissions; } set { _UserPermissions = value; } }
public virtual Employee Employee { get; set; }
}
Второй класс
[Table("UserPermissions")]
public class UserPermissions
{
[Key(),ForeignKey("UserAccount")]
public Guid UserPermissionsId { get; set; }
private Permission _ForUserAccount = new Permission();
public Permission ForUserAccount
{ get { return _ForUserAccount; } set { _ForUserAccount = value; } }
private Permission _ForGainReport = new Permission();
public Permission ForGainReport { get { return _ForGainReport; } set { _ForGainReport = value; } }
private Permission _ForBills = new Permission();
public Permission ForBills { get { return _ForBills; } set { _ForBills = value; } }
private Permission _ForEmployees = new Permission();
public Permission ForEmployees { get { return _ForEmployees; } set { _ForEmployees = value; } }
public virtual UserAccount UserAccount { get; set; }
}
Третий класс сложного типа
[ComplexType]
public class Permission
{
public bool CanAdd { get; set; }
public bool CanModify { get; set; }
public bool CanDelete { get; set; }
public bool CanPreview { get; set; }
public bool CanPrint { get; set; }
public bool CanImport { get; set; }
public bool CanExport { get; set; }
}
Когда я заполняю базу данных, все в порядке, и UserPermissionsTable заполняется соответствующим образом, но когда приложение работает, из этой таблицы не читаются данные, и когда я пытаюсь сохранить изменения из графического интерфейса, я получаю следующее исключение
Exception thrown: 'System.Data.SqlClient.SqlException' in System.Data.dll
Additional information: Violation of PRIMARY KEY constraint 'PK_dbo.UserPermissions'. Cannot insert duplicate key in object 'dbo.UserPermissions'. The duplicate key value is (b3b9e826-defd-e811-8d24-6c71d92c1f7e).
Я не знаю, что на самом деле происходит..
Я проверил и все выглядит хорошо для меня.... пожалуйста, помогите!!!!!!!!!!!!!