2016-09-16 13 views
0

バディークラス(described in this answer)を設定しようとしていたため、モデルからデータベースを更新するたびに、自動生成されたEntity Frameworkクラスの設定が失われることはありません。Entity Frameworkバディークラスの結果タイプ変換エラー

MVCプロジェクトのModelsディレクトリにbuddyクラスを作成しました。このEDMXはソリューションの別のプロジェクトにあります。これは、このエラーでコンパイルに失敗します。

エラーCS0029:\プロジェクト\のBitbucket \カタログ・ツール\ TrinityCatalogTool.Data \ binに\デバッグ\ TrinityCatalogTool.Data:暗黙的に型「TrinityCatalogTool.Data.Details [Cを変換できません。 (112,35)

私は理由を理解できません。バディクラスは元のクラスの一部であるため、元のクラスをバディクラスにキャストできません。私が間違って何をしているのか?


これは私の自動生成されたクラスは、次のようになります。

//------------------------------------------------------------------------------ 
// <auto-generated> 
//  This code was generated from a template. 
// 
//  Manual changes to this file may cause unexpected behavior in your application. 
//  Manual changes to this file will be overwritten if the code is regenerated. 
// </auto-generated> 
//------------------------------------------------------------------------------ 

namespace TrinityCatalogTool.Data 
{ 
    using System; 
    using System.Collections.Generic; 

    public partial class Details 
    { 
     public int detail_id { get; set; } 
     public int parent_id { get; set; } 
     public string short_description { get; set; } 
     public string long_description { get; set; } 
     public string feature1 { get; set; } 
     public string feature2 { get; set; } 
     public string feature3 { get; set; } 
     public string feature4 { get; set; } 
     public string feature5 { get; set; } 
     public string feature6 { get; set; } 
     public string feature7 { get; set; } 
     public string feature8 { get; set; } 

     public virtual Parents Parents { get; set; } 
    } 
} 

そして、これは私が

using System.ComponentModel.DataAnnotations; 

namespace TrinityCatalogTool.Data 
{ 
    [MetadataType(typeof(Details.Metadata))] 
    public partial class Details 
    { 
     private sealed class Metadata 
     { 
      [Display(Name = "Short Description")] 
      public string short_description { get; set; } 
      [Display(Name = "Long Description")] 
      public string long_description { get; set; } 
      [Display(Name = "Feature #1")] 
      public string feature1 { get; set; } 
      [Display(Name = "Feature #2")] 
      public string feature2 { get; set; } 
      [Display(Name = "Feature #3")] 
      public string feature3 { get; set; } 
      [Display(Name = "Feature #4")] 
      public string feature4 { get; set; } 
      [Display(Name = "Feature #5")] 
      public string feature5 { get; set; } 
      [Display(Name = "Feature #6")] 
      public string feature6 { get; set; } 
      [Display(Name = "Feature #7")] 
      public string feature7 { get; set; } 
      [Display(Name = "Feature #8")] 
      public string feature8 { get; set; } 
     } 
    } 
} 
+0

[this](http://stackoverflow.com/questions/3858649/partial-classes-in-separate-dlls)が問題にヒントを与えていますか? –

+0

ありがとう、あなたは頭の爪を打つ。私はバディクラスを自分のEntity Frameworkモデルと同じプロジェクトに移しました。今すぐ動作します。 – Patrick

答えて

1

パーシヴァゴパルさんのコメントのようなルックスを作成したものを私のバディクラスで、問題でした私の部分クラスは、私の自動生成されたクラスと同じプロジェクトに存在する必要があったということです。バディクラスを元のクラスと同じプロジェクトに移動したとき、それはコンパイルされ、期待どおりに機能しました。

関連する問題