2012-01-23 15 views
6

लोड करने में असमर्थ मैंने Entity Connection String को app.config से कोड में स्थानांतरित करने का निर्णय लिया। हालांकि इस तरह यह सेट करने के बाद:इकाई फ्रेमवर्क: निर्दिष्ट मेटाडेटा संसाधन

public static string GetConnectionString() { 
     string connection = ""; 

     SqlConnectionStringBuilder sqlBuilder = new SqlConnectionStringBuilder(); 
     sqlBuilder.DataSource = dbServer; 
     sqlBuilder.InitialCatalog = dbInitialCatalog; 

     sqlBuilder.IntegratedSecurity = false; 
     sqlBuilder.UserID = dbUserName; 
     sqlBuilder.Password = dbPasswWord; 
     sqlBuilder.MultipleActiveResultSets = true; 

     EntityConnectionStringBuilder entity = new EntityConnectionStringBuilder(); 
     // entity.Name = "EntityBazaCRM"; 
     entity.Metadata = @"res://*/Data.System.csdl|res://*/Data.System.ssdl|res://*/Data.System.msl"; 

     entity.Provider = "System.Data.SqlClient"; 
     entity.ProviderConnectionString = sqlBuilder.ToString(); 

     connection = entity.ToString(); 

     return connection; 
    } 

मैं एक अपवाद .Designer.cs में Unable to load the specified metadata resource. फेंक दिया है।

/// <summary> 
    /// Initialize a new EntityBazaCRM object. 
    /// </summary> 
    public EntityBazaCRM(string connectionString) : base(connectionString, "EntityBazaCRM") 
    { 
     this.ContextOptions.LazyLoadingEnabled = true; 
     OnContextCreated(); 
    } 

अगर मैं अपने इकाई निर्माता के अंदर .Name बताएं कि वह एक और अपवाद

"Other keywords are not allowed when the 'Name' keyword is specified." (System.ArgumentException) Exception Message = "Other keywords are not allowed when the 'Name' keyword is specified.", Exception Type = "System.ArgumentException"

मैं जानता हूँ कि मैं कुछ मैं तो बदलना होगा याद कर रहा हूँ कि स्वयं उत्पन्न कोड नए कनेक्शन स्ट्रिंग का उपयोग करता फेंकता लेकिन इसके लिए कहां देखना है?

+0

यहाँ देखें। यह एक तरह से अच्छा जवाब :) http://stackoverflow.com/questions/689355/metadataexception-unable-to-load-the-specified-metadata-resource – Phil

उत्तर

26

this answers लेख और this blog पढ़ने के बाद मैं बदल दिया है:

entity.Metadata = @"res://*/Data.System.csdl|res://*/Data.System.ssdl|res://*/Data.System.msl"; 

करने के लिए:

entity.Metadata = "res://*/"; 

और यह काम करता है :-)

+1

अच्छा समाधान की तरह लग रहा है, लेकिन वहां कोई नुकसान है ऐसा करने में? –

+0

मुझे नहीं पता कि। मैं आज तक उस समय से इसका उपयोग कर रहा हूं;) – MadBoy

+0

मेरे लिए काम किया, हालांकि मुझे कुछ चिंता है कि क्यों ... – NibblyPig

संबंधित मुद्दे