public class CommandObject
{
private readonly MyContext myContext;
public CommandObject(MyContext myContext)
{
this.myContext = myContext;
}
public void CreateFoo()
{
myContext.Foos.Add(new Foo());
myContext.SaveChanges();
}
}
public class SeparateFooService
{
private readonly CommandObject commandObject;
public SeparateFooService(CommandObject commandObject)
{
this.commandObject = commandObject;
}
public void CreateTwoFoos()
{
commandObject.CreateFoo();
commandObject.CreateFoo();
}
}
public class TransactionalFooService
{
private readonly MyContext myContext;
private readonly CommandObject commandObject;
public TransactionalFooService(MyContext myContext, CommandObject commandObject)
{
this.myContext = myContext;
this.commandObject = commandObject;
}
public void CreateTwoFoos()
{
using (var transaction = myContext.Database.BeginTransaction())
{
commandObject.CreateFoo();
commandObject.CreateFoo();
transaction.Commit();
}
}
}
Meine Frage betrifft myContext und commandObject in TransactionalFooService. Unter der Annahme, dass myContext für einen Gültigkeitsbereich konfiguriert ist, sind dann sowohl myContext, der eine Abhängigkeit von TransactionalFooService darstellt, als auch myContext, der eine Abhängigkeit von commandObject (dem commandObject in TransactionalFooService) darstellt, identisch?
public void CreateTwoFoos() { using (var transaction = myContext.Database.BeginTransaction()) { commandObject.CreateFoo(); commandObject.CreateFoo();
transaction.Commit(); } } } [/code] Meine Frage betrifft myContext und commandObject in TransactionalFooService. Unter der Annahme, dass myContext für einen Gültigkeitsbereich konfiguriert ist, sind dann sowohl myContext, der eine Abhängigkeit von TransactionalFooService darstellt, als auch myContext, der eine Abhängigkeit von commandObject (dem commandObject in TransactionalFooService) darstellt, identisch?
Ich habe ein ASP.NET Core 8-Projekt mit Entity Framework Core. Die Verbindungszeichenfolge wird aus web.config im Stammordner übernommen. Beim Debuggen in Visual Studio 2022 habe ich Hot Reload...
Ich arbeite an einem Projekt mit Entity Framework Core 3.1 und muss die Gesamterfahrung eines Kandidaten in Jahren zusammenfassen. In meinem Code habe ich eine CvExperiences-Tabelle mit den Feldern...
Ich versuche, komplexe Datensätze mit mehreren Ebenen verschachtelter Felder in C# / ASP.NET Core / Entity Framework Core effizient zu bearbeiten.
Ich habe eine kleine Test-App mit EF-Modellen...
Ich verwende Entity Framework Core in einer ASP.NET Core-Anwendung und Controller-Aktion und habe weder am Arbeitscode noch an der Datenbank etwas geändert, kann aber nicht sagen, welche Abfrage von...