ASP.NET Core MetaDataType Attribute not workingAdd data annotations to a class generated by entity frameworkASP.NET Core MVC - Model Binding : Bind an interface model using the attribute [FromBody] (BodyModelBinder)ModelMetadataType has no effect on model in asp.net core 2.0Loading MetaData in Aspnet CoreCan I use Partial Classes to determine how data models get Json Serialized in .Net Core 2.0 APISeparating the serialization metadata from the implementation of a data contract?How to transfer DataAnnotations from model to viewModel in asp.net core?Why is Entity Framework data annotation not getting picked upWhat does the [Flags] Enum Attribute mean in C#?Most Useful AttributesFile Upload ASP.NET MVC 3.0.net mvc 2 validation: summing up values of several attributesHow does the StringLengthAttribute work?MVC change ModelBinder unit testMetadataType and DataAnnotations not WorkingValidation of a Dropdown which property comes from model but created from a RenderActionHow to handle DataAnnotation RequiredField(ErrorMessage…) using EntityTypeConfigurationASP Core MVC Scaffolding SelectList (RC1) not populating data
How to say in German "enjoying home comforts"
What is the word for reserving something for yourself before others do?
Is "remove commented out code" correct English?
I would say: "You are another teacher", but she is a woman and I am a man
What to put in ESTA if staying in US for a few days before going on to Canada
A reference to a well-known characterization of scattered compact spaces
Is it possible to run Internet Explorer on OS X El Capitan?
Is it inappropriate for a student to attend their mentor's dissertation defense?
Alternative to sending password over mail?
Has there ever been an airliner design involving reducing generator load by installing solar panels?
Can I use a neutral wire from another outlet to repair a broken neutral?
Neighboring nodes in the network
Were any external disk drives stacked vertically?
Should I tell management that I intend to leave due to bad software development practices?
Is there a hemisphere-neutral way of specifying a season?
Twin primes whose sum is a cube
Took a trip to a parallel universe, need help deciphering
Why is consensus so controversial in Britain?
Stopping power of mountain vs road bike
Brothers & sisters
Is Lorentz symmetry broken if SUSY is broken?
How can I tell someone that I want to be his or her friend?
Anagram holiday
What is the most common color to indicate the input-field is disabled?
ASP.NET Core MetaDataType Attribute not working
Add data annotations to a class generated by entity frameworkASP.NET Core MVC - Model Binding : Bind an interface model using the attribute [FromBody] (BodyModelBinder)ModelMetadataType has no effect on model in asp.net core 2.0Loading MetaData in Aspnet CoreCan I use Partial Classes to determine how data models get Json Serialized in .Net Core 2.0 APISeparating the serialization metadata from the implementation of a data contract?How to transfer DataAnnotations from model to viewModel in asp.net core?Why is Entity Framework data annotation not getting picked upWhat does the [Flags] Enum Attribute mean in C#?Most Useful AttributesFile Upload ASP.NET MVC 3.0.net mvc 2 validation: summing up values of several attributesHow does the StringLengthAttribute work?MVC change ModelBinder unit testMetadataType and DataAnnotations not WorkingValidation of a Dropdown which property comes from model but created from a RenderActionHow to handle DataAnnotation RequiredField(ErrorMessage…) using EntityTypeConfigurationASP Core MVC Scaffolding SelectList (RC1) not populating data
.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty height:90px;width:728px;box-sizing:border-box;
I'm using the MetaDataType Attribute on my domain model class. It it supposed to move the attribute information from the referenced class into the class that the MetadataType attribute has been set.
But it doesn't do as advertised. What is causing the issue here?
[MetadataType(typeof(ComponentModelMetaData))]
public partial class Component
public int Id get; set;
public string Name get; set;
public ICollection<Repo> Repos get; set;
public string Description get; set;
public class ComponentModelMetaData
[Required(ErrorMessage = "Name is required.")]
[StringLength(30, MinimumLength = 3, ErrorMessage = "Name length should be more than 3 symbols.")]
public string Name get; set;
public ICollection<Repo> Repos get; set;
[Required(ErrorMessage = "Description is required.")]
public string Description get; set;
c# asp.net-core data-annotations
add a comment |
I'm using the MetaDataType Attribute on my domain model class. It it supposed to move the attribute information from the referenced class into the class that the MetadataType attribute has been set.
But it doesn't do as advertised. What is causing the issue here?
[MetadataType(typeof(ComponentModelMetaData))]
public partial class Component
public int Id get; set;
public string Name get; set;
public ICollection<Repo> Repos get; set;
public string Description get; set;
public class ComponentModelMetaData
[Required(ErrorMessage = "Name is required.")]
[StringLength(30, MinimumLength = 3, ErrorMessage = "Name length should be more than 3 symbols.")]
public string Name get; set;
public ICollection<Repo> Repos get; set;
[Required(ErrorMessage = "Description is required.")]
public string Description get; set;
c# asp.net-core data-annotations
add a comment |
I'm using the MetaDataType Attribute on my domain model class. It it supposed to move the attribute information from the referenced class into the class that the MetadataType attribute has been set.
But it doesn't do as advertised. What is causing the issue here?
[MetadataType(typeof(ComponentModelMetaData))]
public partial class Component
public int Id get; set;
public string Name get; set;
public ICollection<Repo> Repos get; set;
public string Description get; set;
public class ComponentModelMetaData
[Required(ErrorMessage = "Name is required.")]
[StringLength(30, MinimumLength = 3, ErrorMessage = "Name length should be more than 3 symbols.")]
public string Name get; set;
public ICollection<Repo> Repos get; set;
[Required(ErrorMessage = "Description is required.")]
public string Description get; set;
c# asp.net-core data-annotations
I'm using the MetaDataType Attribute on my domain model class. It it supposed to move the attribute information from the referenced class into the class that the MetadataType attribute has been set.
But it doesn't do as advertised. What is causing the issue here?
[MetadataType(typeof(ComponentModelMetaData))]
public partial class Component
public int Id get; set;
public string Name get; set;
public ICollection<Repo> Repos get; set;
public string Description get; set;
public class ComponentModelMetaData
[Required(ErrorMessage = "Name is required.")]
[StringLength(30, MinimumLength = 3, ErrorMessage = "Name length should be more than 3 symbols.")]
public string Name get; set;
public ICollection<Repo> Repos get; set;
[Required(ErrorMessage = "Description is required.")]
public string Description get; set;
c# asp.net-core data-annotations
c# asp.net-core data-annotations
edited Oct 7 '17 at 23:22
Camilo Terevinto
19.6k63969
19.6k63969
asked Jan 3 '16 at 13:15
MetaMeta
119110
119110
add a comment |
add a comment |
2 Answers
2
active
oldest
votes
ASP.NET Core uses
Microsoft.AspNetCore.Mvc.Core.**ModelMetadataType**
instead of
System.ComponentModel.DataAnnotations.**MetadataType**
source
Try changing your attribute to [ModelMetadataType(typeof(ComponentModelMetaData))]
4
My deepest thanks for finding Microsoft.AspNetCore.Mvc.ModelMetadataTypeAttribute for .NET Core 1.0 ... different name, different namespace ... not hard to find. Anyway, this is the correct answer, since the partial class Component appears to be the model declaration. I prefer to use a partial class named the same and in the same logical namespace as the model to apply Validate and the metadata's annotations to the model. That way, if I regenerate the model from the database, I don't lose my edits.
– Gopher
Aug 10 '16 at 14:52
add a comment |
This is how I solved the same issue, I hope this solve your problem.
Entity class:
namespace CoreProject.Persistence.EFCore
public partial class User
public User()
Reader = new HashSet<Reader>();
Writer = new HashSet<Writer>();
public int UserId get; set;
public string Email get; set;
public string Password get; set;
public string PasswordHashKey get; set;
public byte Role get; set;
public string FirstName get; set;
public string LastName get; set;
public DateTime CreatedUtc get; set;
public DateTime LastUpdateUtc get; set;
public byte Status get; set;
public bool Deleted get; set;
public DateTime? ActivatedUtc get; set;
public bool Test get; set;
public virtual ICollection<Reader> Reader get; set;
public virtual ICollection<Writer> Writer get; set;
Metadata:
namespace CoreProject.Persistence.EFCore
[ModelMetadataType(typeof(IUserMetadata))]
public partial class User : IUserMetadata
public string FullName => FirstName + " " + LastName;
public interface IUserMetadata
[JsonProperty(PropertyName = "Id")]
int UserId get; set;
[JsonIgnore]
string Password get; set;
[JsonIgnore]
string PasswordHashKey get; set;
[JsonIgnore]
byte Role get; set;
Good luck...
add a comment |
Your Answer
StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");
StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);
else
createEditor();
);
function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);
);
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f34576921%2fasp-net-core-metadatatype-attribute-not-working%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
2 Answers
2
active
oldest
votes
2 Answers
2
active
oldest
votes
active
oldest
votes
active
oldest
votes
ASP.NET Core uses
Microsoft.AspNetCore.Mvc.Core.**ModelMetadataType**
instead of
System.ComponentModel.DataAnnotations.**MetadataType**
source
Try changing your attribute to [ModelMetadataType(typeof(ComponentModelMetaData))]
4
My deepest thanks for finding Microsoft.AspNetCore.Mvc.ModelMetadataTypeAttribute for .NET Core 1.0 ... different name, different namespace ... not hard to find. Anyway, this is the correct answer, since the partial class Component appears to be the model declaration. I prefer to use a partial class named the same and in the same logical namespace as the model to apply Validate and the metadata's annotations to the model. That way, if I regenerate the model from the database, I don't lose my edits.
– Gopher
Aug 10 '16 at 14:52
add a comment |
ASP.NET Core uses
Microsoft.AspNetCore.Mvc.Core.**ModelMetadataType**
instead of
System.ComponentModel.DataAnnotations.**MetadataType**
source
Try changing your attribute to [ModelMetadataType(typeof(ComponentModelMetaData))]
4
My deepest thanks for finding Microsoft.AspNetCore.Mvc.ModelMetadataTypeAttribute for .NET Core 1.0 ... different name, different namespace ... not hard to find. Anyway, this is the correct answer, since the partial class Component appears to be the model declaration. I prefer to use a partial class named the same and in the same logical namespace as the model to apply Validate and the metadata's annotations to the model. That way, if I regenerate the model from the database, I don't lose my edits.
– Gopher
Aug 10 '16 at 14:52
add a comment |
ASP.NET Core uses
Microsoft.AspNetCore.Mvc.Core.**ModelMetadataType**
instead of
System.ComponentModel.DataAnnotations.**MetadataType**
source
Try changing your attribute to [ModelMetadataType(typeof(ComponentModelMetaData))]
ASP.NET Core uses
Microsoft.AspNetCore.Mvc.Core.**ModelMetadataType**
instead of
System.ComponentModel.DataAnnotations.**MetadataType**
source
Try changing your attribute to [ModelMetadataType(typeof(ComponentModelMetaData))]
edited Oct 7 '17 at 23:23
Camilo Terevinto
19.6k63969
19.6k63969
answered May 22 '16 at 15:07
Guilherme DuarteGuilherme Duarte
2,42112231
2,42112231
4
My deepest thanks for finding Microsoft.AspNetCore.Mvc.ModelMetadataTypeAttribute for .NET Core 1.0 ... different name, different namespace ... not hard to find. Anyway, this is the correct answer, since the partial class Component appears to be the model declaration. I prefer to use a partial class named the same and in the same logical namespace as the model to apply Validate and the metadata's annotations to the model. That way, if I regenerate the model from the database, I don't lose my edits.
– Gopher
Aug 10 '16 at 14:52
add a comment |
4
My deepest thanks for finding Microsoft.AspNetCore.Mvc.ModelMetadataTypeAttribute for .NET Core 1.0 ... different name, different namespace ... not hard to find. Anyway, this is the correct answer, since the partial class Component appears to be the model declaration. I prefer to use a partial class named the same and in the same logical namespace as the model to apply Validate and the metadata's annotations to the model. That way, if I regenerate the model from the database, I don't lose my edits.
– Gopher
Aug 10 '16 at 14:52
4
4
My deepest thanks for finding Microsoft.AspNetCore.Mvc.ModelMetadataTypeAttribute for .NET Core 1.0 ... different name, different namespace ... not hard to find. Anyway, this is the correct answer, since the partial class Component appears to be the model declaration. I prefer to use a partial class named the same and in the same logical namespace as the model to apply Validate and the metadata's annotations to the model. That way, if I regenerate the model from the database, I don't lose my edits.
– Gopher
Aug 10 '16 at 14:52
My deepest thanks for finding Microsoft.AspNetCore.Mvc.ModelMetadataTypeAttribute for .NET Core 1.0 ... different name, different namespace ... not hard to find. Anyway, this is the correct answer, since the partial class Component appears to be the model declaration. I prefer to use a partial class named the same and in the same logical namespace as the model to apply Validate and the metadata's annotations to the model. That way, if I regenerate the model from the database, I don't lose my edits.
– Gopher
Aug 10 '16 at 14:52
add a comment |
This is how I solved the same issue, I hope this solve your problem.
Entity class:
namespace CoreProject.Persistence.EFCore
public partial class User
public User()
Reader = new HashSet<Reader>();
Writer = new HashSet<Writer>();
public int UserId get; set;
public string Email get; set;
public string Password get; set;
public string PasswordHashKey get; set;
public byte Role get; set;
public string FirstName get; set;
public string LastName get; set;
public DateTime CreatedUtc get; set;
public DateTime LastUpdateUtc get; set;
public byte Status get; set;
public bool Deleted get; set;
public DateTime? ActivatedUtc get; set;
public bool Test get; set;
public virtual ICollection<Reader> Reader get; set;
public virtual ICollection<Writer> Writer get; set;
Metadata:
namespace CoreProject.Persistence.EFCore
[ModelMetadataType(typeof(IUserMetadata))]
public partial class User : IUserMetadata
public string FullName => FirstName + " " + LastName;
public interface IUserMetadata
[JsonProperty(PropertyName = "Id")]
int UserId get; set;
[JsonIgnore]
string Password get; set;
[JsonIgnore]
string PasswordHashKey get; set;
[JsonIgnore]
byte Role get; set;
Good luck...
add a comment |
This is how I solved the same issue, I hope this solve your problem.
Entity class:
namespace CoreProject.Persistence.EFCore
public partial class User
public User()
Reader = new HashSet<Reader>();
Writer = new HashSet<Writer>();
public int UserId get; set;
public string Email get; set;
public string Password get; set;
public string PasswordHashKey get; set;
public byte Role get; set;
public string FirstName get; set;
public string LastName get; set;
public DateTime CreatedUtc get; set;
public DateTime LastUpdateUtc get; set;
public byte Status get; set;
public bool Deleted get; set;
public DateTime? ActivatedUtc get; set;
public bool Test get; set;
public virtual ICollection<Reader> Reader get; set;
public virtual ICollection<Writer> Writer get; set;
Metadata:
namespace CoreProject.Persistence.EFCore
[ModelMetadataType(typeof(IUserMetadata))]
public partial class User : IUserMetadata
public string FullName => FirstName + " " + LastName;
public interface IUserMetadata
[JsonProperty(PropertyName = "Id")]
int UserId get; set;
[JsonIgnore]
string Password get; set;
[JsonIgnore]
string PasswordHashKey get; set;
[JsonIgnore]
byte Role get; set;
Good luck...
add a comment |
This is how I solved the same issue, I hope this solve your problem.
Entity class:
namespace CoreProject.Persistence.EFCore
public partial class User
public User()
Reader = new HashSet<Reader>();
Writer = new HashSet<Writer>();
public int UserId get; set;
public string Email get; set;
public string Password get; set;
public string PasswordHashKey get; set;
public byte Role get; set;
public string FirstName get; set;
public string LastName get; set;
public DateTime CreatedUtc get; set;
public DateTime LastUpdateUtc get; set;
public byte Status get; set;
public bool Deleted get; set;
public DateTime? ActivatedUtc get; set;
public bool Test get; set;
public virtual ICollection<Reader> Reader get; set;
public virtual ICollection<Writer> Writer get; set;
Metadata:
namespace CoreProject.Persistence.EFCore
[ModelMetadataType(typeof(IUserMetadata))]
public partial class User : IUserMetadata
public string FullName => FirstName + " " + LastName;
public interface IUserMetadata
[JsonProperty(PropertyName = "Id")]
int UserId get; set;
[JsonIgnore]
string Password get; set;
[JsonIgnore]
string PasswordHashKey get; set;
[JsonIgnore]
byte Role get; set;
Good luck...
This is how I solved the same issue, I hope this solve your problem.
Entity class:
namespace CoreProject.Persistence.EFCore
public partial class User
public User()
Reader = new HashSet<Reader>();
Writer = new HashSet<Writer>();
public int UserId get; set;
public string Email get; set;
public string Password get; set;
public string PasswordHashKey get; set;
public byte Role get; set;
public string FirstName get; set;
public string LastName get; set;
public DateTime CreatedUtc get; set;
public DateTime LastUpdateUtc get; set;
public byte Status get; set;
public bool Deleted get; set;
public DateTime? ActivatedUtc get; set;
public bool Test get; set;
public virtual ICollection<Reader> Reader get; set;
public virtual ICollection<Writer> Writer get; set;
Metadata:
namespace CoreProject.Persistence.EFCore
[ModelMetadataType(typeof(IUserMetadata))]
public partial class User : IUserMetadata
public string FullName => FirstName + " " + LastName;
public interface IUserMetadata
[JsonProperty(PropertyName = "Id")]
int UserId get; set;
[JsonIgnore]
string Password get; set;
[JsonIgnore]
string PasswordHashKey get; set;
[JsonIgnore]
byte Role get; set;
Good luck...
edited Mar 8 at 0:04
answered Feb 24 at 12:57
Javier ContrerasJavier Contreras
114
114
add a comment |
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f34576921%2fasp-net-core-metadatatype-attribute-not-working%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown