I discovered an extremely strange behavior in Visual Studio 2017 in combination with Entity Framework I have the following instruction:
public ActionResult AngebotAufheben(int sachkostId)
{
Sachkost sachkost = db.sachkosten.Find(sachkostId);
sachkost.ausgewaehltesAngebot = null;
if (sachkost.ausgewaehltesAngebot != null)
sachkost.ausgewaehltesAngebot = null;
db.Entry(sachkost).State = EntityState.Modified;
db.SaveChanges();
return RedirectToAction("Edit", new { id = sachkostId });
}
"ausgewaehltesAngebot" is of type "Angebot" , and both "Sachkost "and "Angebot" are managed through the Entity Framework.
The strange thing for me is that VS ignores
sachkost.ausgewaehltesAngebot = null;
and
if (sachkost.ausgewaehltesAngebot != null)
is not false.
If i set a breakpoint at
db.Entry(sachkost).State = EntityState.Modified;
VS tells me that sachkost.ausgewaehltesAngebot is of type System.Data.Entity.DaynamicProxies.Angebot_...
Is this a form of EF magic and intentional? I definitely do not understand it.
Many thanks for the help.
Update: Here is my Definition for Sachkost:
public class Sachkost
{
public int SachkostId { get; set; }
public string Name { get; set; }
public KategorienSachkost kategorieNummer { get; set; }
public decimal geplanteKosten { get; set; }
public virtual Angebot ausgewaehltesAngebot { get; set; }
public virtual List<Angebot> angebote { get; set; }
public int massnahmeID { get; set; };
[ForeignKey("massnahmeID")]
public virtual Massnahme massnahme { get; set; }
public string erstellerId { get; set; };
[ForeignKey("erstellerId")]
public virtual Mitarbeiter ersteller { get; set; }
}
And i am using EF6
Comments
Post a Comment