I've been staring at this for a long time now and cannot see the problem.
I've generated some POCO classes using EF4 and POCO generator.
I'm trying to use the MetadataType attribute to create "buddy" classes which I can use in my View (asp.net MVC) and take advantage of data annotations.
So, I have a domain entity (POCO) called Contact. That is in a project called BreakAwayEntities in the namespace BreakAwayEntities.
I've created a public partial class in my View's project (WebUI). It is this:
namespace BreakAwayEntities
{
[MetadataType(typeof(ContactMetadataSource))]
public partial class Contact
{
internal sealed class ContactMetadataSource
{
[HiddenInput(DisplayValue = false)]
public int ContactID { get; set; }
[Display(Name = "First Name")]
public string FirstName { get; set; }
[Display(Name = "Last Name")]
public string LastName { get; set; }
public string Title { get; set; }
}
}
}
However, I am treated to the following error message:
Error 10 Cannot implicitly convert type 'System.Collections.Generic.List [c:\Program Files (x86)\Reference Assemblies\Microsoft\Framework.NETFramework\v4.0\mscorlib.dll]' to 'System.Collections.Generic.List [c:\Program Files (x86)\Reference Assemblies\Microsoft\Framework.NETFramework\v4.0\mscorlib.dll]' F:\Code\Sandpit\GetAwayBreaks\WebUI\Controllers\CustomerController.cs 29 38 WebUI
For some reason, the wiring up is not working. The namespace of the partial classes is the same, but they are in different projects. That shouldn't matter? The Contact class when used in the View does not reveal a single property. It should be exposing all the properties of the POCO, as augmented by the MetadataType.
If I am missing an assembly, I'm not getting any hints as to what it might be.
What have I missed? Do I need to register something in Global.asax? Thanks
Partial classes can only exist within one project.
http://msdn.microsoft.com/en-us/library/wa80x488(v=vs.100).aspx
More specifically,
All partial-type definitions meant to be parts of the same type must be defined in the same assembly and the same module (.exe or .dll file). Partial definitions cannot span multiple modules.