Make sure that the MainClass namespace is the same as Partial and has the same attributes. This is my decision.
example:
Metadata: Create It Anywhere You Want
public class FormMetadata { public int Id { get; set; } public string Description { get; set; } public Nullable<bool> IsEnable { get; set; } public Nullable<System.DateTime> CreationDate { get; set; } public int CompanieId { get; set; } public string RegularExpression { get; set; } public virtual ICollection<Field> Fields { get; set; } [JsonIgnore] public virtual Company Company { get; set; } }
Mainclass
namespace Transactions.Model { public partial class Form { [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Usage", "CA2214:DoNotCallOverridableMethodsInConstructors")] public Form() { this.Fields = new HashSet<Field>(); } public int Id { get; set; } public string Description { get; set; } public Nullable<bool> IsEnable { get; set; } public Nullable<System.DateTime> CreationDate { get; set; } public int CompanieId { get; set; } public string RegularExpression { get; set; } [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Usage", "CA2227:CollectionPropertiesShouldBeReadOnly")] public virtual ICollection<Field> Fields { get; set; } public virtual Company Company { get; set; } } }
Partial use of MetadataType
namespace Transactions.Model { [MetadataTypeAttribute(typeof(FormMetadata))] public partial class Form { } }
Should you have problems creating a partial class in the same namespace? Do not worry
- Create a folder
- Create a partial class in this folder
- Change the namespace to the same from MainClass
source share