kullanıcı kodu işlenmedi ya bir create
, edit
ve delete
veritabanına kayıt.bir istisna EntityFramework.Core.dll oluştu ama hiç ilişkilendirilmiş bir <code>ActivityLogType</code> ilişkili <code>long</code> değeri elde çalışıyorum
Gerekli olan bir denetim/etkinlik günlüğü için kullanılır.
public enum ActivityLogType
{
Create = 1,
Update = 2,
Delete = 3
}
Benim alıcı yöntemi:
public ActivityType GetType(ActivityLogType type)
{
var id = (long)type;
Console.WriteLine(id); // <---- this produces a 1 in the console. So the cast works?
return _context.ActivityTypes.Where(x => x.Id == id).FirstOrDefault(); // <-- This line throws the error
}
GÜNCELLEME istenilen çıktıyı almak için (long)ActivityLogType.Create
kullanarak önerdi 1
un-şanslı. Bu çalıştı: (Hala çalışmıyor)
public ActivityType GetType(ActivityLogType type)
{
switch (type)
{
case ActivityLogType.Create:
return _context.ActivityTypes.Where(x => x.Id == (long)ActivityLogType.Create).FirstOrDefault();
case ActivityLogType.Update:
return _context.ActivityTypes.Where(x => x.Id == (long)ActivityLogType.Update).FirstOrDefault();
case ActivityLogType.Delete:
return _context.ActivityTypes.Where(x => x.Id == (long)ActivityLogType.Delete).FirstOrDefault();
default:
return null;
}
}
İşte GÜNCELLEME 2
olduğunu Bu deneyebilirsiniz
public class ActivityType
{
public ActivityType()
{
this.Activities = new HashSet<Activity>();
}
[Key, DatabaseGenerated(DatabaseGeneratedOption.Identity)]
public long Id { get; set; }
[Display(Name = "Label")]
public string Label { get; set; }
[Display(Name = "Display Order")]
public int Order { get; set; }
[Display(Name = "Is Active")]
public bool IsActive { get; set; }
[Display(Name = "Activities")]
public virtual ICollection<Activity> Activities { get; set; }
}
ve ne 'ActivityTypes olduğunu 'burada –
@ un şanssızlık bir' DbSet ' –
Rijnhardt
@ şanssız' genel sanal DbSet < ActivityType> ActivityTypes {get; set; } '' dbContext.cs'imde – Rijnhardt