In the Entity Framework (database first) I am trying to add some data annotations to the generated classes.
In general: I have class X:
namespace Info { using System; using System.Collections.Generic; public partial class X { public string SomeProperty {get; set;} ... } }
I want the SomeProperty property to SomeProperty ignored when serialized in JSON, so in App_Code/Metadata I create an X.cs class and add some metadata:
namespace Info { public class XMetaData { [JsonIgnore] public string SomeProperty{get; set;} } [MetadataType(typeof(XMetaData))] public partial class X { } }
Above, I manually changed the namespace from Info.App_Code.Metadata to Info to combine partial classes.
However, in all places where I use class X, I have a warning
The type Info.X in '.../Info/App_Code/Metadata/X.cs ' conflicts with the imported type Info.X in '.../Info/X.cs'. Using the type defined in '.../Info/App_Code/Metadata/X.cs '
I expected both partial classes to be merged, however all occurrences relate to this empty class X.
Does anyone know what I am missing?
source share