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:

 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;}

Edit this Article Core 3.1 mvc core errors web forms core tutorial Technology published
Was this page helpful?
Yes Yes! this solution to the problem was helpful. No No! this solution to the problem was not helpful.. Leave ErnesTech Feedback.Feedback
If you log in, you will be notified when someone leaves a comment.

Other users would like to know if this solution helped you.

Your Session is Ending
Login to Continue

© 2021 - ErnesTech - Privacy