I have been trying to setup a buddy class (described in this answer) so my annotations I setup on the auto generated Entity Framework classes don't get lost everytime I update the model from the database.
I created the buddy class in the Models directory of my MVC project, The EDMX is in another project in the solution. It fails to compile with this error:
Error CS0029: Cannot implicitly convert type 'TrinityCatalogTool.Data.Details [C:\Projects\Bitbucket\catalog-tool\TrinityCatalogTool.Data\bin\Debug\TrinityCatalogTool.Data.dll]' to 'TrinityCatalogTool.Data.Details [C:\Projects\Bitbucket\catalog-tool\TrinityCatalogTool\Models\Metadata.cs(9)]' (112, 35)
I don't understand why it would fail to cast the original class to my buddy class since the buddy class is a partial of that original. Any idea what I am doing wrong?
This is what my auto generated class looks like:
//------------------------------------------------------------------------------
// <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; }
}
}
And this is what my buddy class I created looks like
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; }
}
}
}