Ich habe ein einfaches Projekt mit ASP.Net MVC Vorlage in Visual Studio 2013 Express für Web erstellt. Es verwendet keine Authentifizierung. Dann habe ich EntityFramework
(v6.0.1), EntityFramework.SqlServerCompact
Pakete installiert.DbContext nicht mit SQL Server Compact in ASP.Net MVC
Mein DbContext Klasse ist sehr einfach:
public class EditTestContext : DbContext
{
public EditTestContext() : base("EditTestContext")
{
}
public EditTestContext(string connectionString) : base(connectionString)
{
}
protected override void OnModelCreating(DbModelBuilder modelBuilder)
{
Database.SetInitializer(
new DropCreateDatabaseIfModelChanges<EditTestContext>());
modelBuilder.Conventions.Remove<PluralizingTableNameConvention>();
modelBuilder.Configurations.Add(new EditTestConfig());
}
}
Das eigentliche Kontextobjekt in der Einheit der Arbeitsklasse erstellt wird:
public class EditTestUoW:IEditTestUoW,IDisposable
{
private DbContext dbContext;
public EditTestUoW()
{
CreateDbContext();
}
private void CreateDbContext()
{
dbContext = new EditTestContext();//NEW DBCONTEXT OBJECT IS CREATED
dbContext.Configuration.LazyLoadingEnabled = false;
dbContext.Configuration.ProxyCreationEnabled = false;
dbContext.Configuration.ValidateOnSaveEnabled = false;
}
public IRepository<EditTestModel> EditTestRepo
{
get
{
return new EFRepository<EditTestModel>(dbContext);
}
}
}
Die Verbindungszeichenfolge verwendet wird, ist:
<add name="EditTestContext" connectionString="Data Source=
|DataDirectory|EditTestDb.sdf;Max Database Size=256;
Max Buffer Size=1024;File Mode=Shared Read;
Persist Security Info=False;" providerName="System.Data.SqlServerCe.4.0" />
Jetzt, wenn ich versuche, auf etwas zugreifen mit diesem Kontext wie:
var rep=UoW.EditTestRepo;
var list=rep.GetAll().ToList();
ich folgende Ausnahme auf rep.GetAll()
Funktion bin immer:
System.InvalidOperationException: Sequenz enthält kein Anpassungselement
Auf tiefer, IQueryable
von Repository-Klasse Graben (DbSet<EditTest>
) wirft folgende Ausnahme:
The context cannot be used while the model is being created. This exception may
be thrown if the context is used inside the OnModelCreating method or if the same
context instance is accessed by multiple threads concurrently. Note that instance
members of DbContext and related classes are not guaranteed to be thread safe.
Ich dachte, es könnte durchverursacht worden sein 10, aber es ist immer noch da, auch nachdem ich es entfernt habe.
Was mache ich hier falsch oder etwas (etwas Montageanleitung etc.) fehlt?
Sie sparen meine Meinung! Ich bin verrückt geworden !! – wilver
Ich hatte die gleiche Ausnahme, als ich die Methode 'Property (d => d.BTCValue) .HasPrecision (24, 8)' mit SQL CE aufgerufen habe. Danke, dass du den Grund klar gemacht hast! – Andras
Datum, smalldate und Text scheint auch nicht zu gut zu passen –