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.


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





© 2024 - ErnesTech - Privacy
E-Commerce Return Policy