2012-01-23 28 views
6

Entity Connection Stringapp.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"

別の例外がスローされますそれを探す場所はどこですか?

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

へ:

+0

はここを参照してください:-)動作します。これは良い答えです:) http://stackoverflow.com/questions/689355/metadataexception-unable-to-load-the-specified-metadata-resource – Phil

答えて

26

this answers記事とthis blogを読んだ後、私は変更

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

そして、それは

+1

良い解決策のように見えますが、何らかの害がありますこれを行うには? –

+0

それはわかりません。私は今日までその時からそれを使用しています;) – MadBoy

+0

私はなぜか心配していますが、私のために働いた... – NibblyPig

関連する問題