Please Login to Continue

Free Software Development Articles.Email List

Advertise Here

ASP.Net Core 2.2 Not Required Field in Data Model. DataAnnotations NotMapped or Optional in DotNet Core 2.2

Question: How can I make a Field or Class property in a POCO Data Model not required or Optional in DotNet Core 2.2.

Answer: Prefix the Class Property with a [NotMapped] attribute for the field to be optional or not required, see example below:

 [NotMapped]
 public string predictedFakeNews { get; set; }

//If you are using property as an integer then just prefix it with a question mark after a type which is an integer.
public int? number {get; set;}

//If you want to make a set attribute private then do as follow

public int? number {get; private set;}
asp.net Core 3.1 asp.net mvc asp.net core errors asp.net web forms asp.net core tutorial Technology published
Buy Me Coffee

Was this page helpful?

Yes Yes! this solution to the problem was helpful. No No! this solution to the problem was not helpful..



© 2020 - ErnesTech - Privacy