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 versuche derzeit, einen Einheit /Integrationstest zu schreiben, indem ich den Anbieter von Memory -Datenbank unter Verwendung eines Memory -Datenbankanbieters zu schreiben habe. Entity Framework...
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 habe eine Microsoft SQL Server -Tabelle namens Log , in der ich eine große Anzahl von Protokolleinträgen speichere. Die typische Abfrage besteht darin, Protokollreihen für die letzten Tage,...