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.


Please Login to see the rest of the answer

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

Write an Article
If you log in, you will be notified when someone leaves a comment.

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


© 2022 - ErnesTech - Privacy