में SQL सर्वर कॉम्पैक्ट के साथ प्रारंभ नहीं कर रहा है मैंने वेब के लिए विजुअल स्टडीशन 2013 एक्सप्रेस में एएसपी.NET एमवीसी टेम्पलेट का उपयोग करके एक साधारण प्रोजेक्ट बनाया है। यह किसी प्रमाणीकरण का उपयोग नहीं करता है। फिर मैंने EntityFramework
(v6.0.1), EntityFramework.SqlServerCompact
पैकेज स्थापित किए।डीबीकॉन्टेक्स्ट एएसपी.NET एमवीसी
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());
}
}
वास्तविक संदर्भ वस्तु काम वर्ग के यूनिट में बन जाता है:
मेरे DbContext वर्ग बहुत सरल है
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);
}
}
}
कनेक्शन स्ट्रिंग इस्तेमाल किया जा रहा है:
<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" />
अब जब मैं इस संदर्भ का उपयोग कर किसी भी चीज़ तक पहुंचने का प्रयास करता हूं जैसे:
var rep=UoW.EditTestRepo;
var list=rep.GetAll().ToList();
मैं rep.GetAll()
समारोह पर निम्नलिखित अपवाद हो रही है:
System.InvalidOperationException: अनुक्रम कोई मिलता-जुलता तत्व
भंडार वर्ग से गहरी, IQueryable
खुदाई पर शामिल (DbSet<EditTest>
) निम्नलिखित अपवाद फेंक है:
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.
मैंने सोचा कि यहके कारण हो सकता है 10, लेकिन इसे हटाए जाने के बाद भी यह अभी भी है।
मैं यहां क्या गलत कर रहा हूं या कुछ (कुछ असेंबली संदर्भ इत्यादि) गायब है?
आप मेरा दिमाग बचाओ! मैं उसके लिए पागल हो रहा था !! – wilver
जब मैंने 'संपत्ति (डी => डी। बीटीसीवैल्यू) कहा था, तो मुझे वही अपवाद था। एसएसई सीईसी के साथ प्रोसेस (24, 8) 'विधि। कारण स्पष्ट करने के लिए धन्यवाद! – Andras
दिनांक, smalldate और पाठ अच्छी तरह से फिट नहीं लग रहा है –