Need to check If body data Null and if Null filed, no need to check the particular WHERE clause.
How can I add multiple WHERE and OR clauses with NULL checking?
In CountryDialCodeFields, some fields can be null sometimes.
public class CountryDialCodeFields
{
public string countryCode { get; set; }
public string countryName { get; set; }
public string dialCode { get; set; }
public string currencyCode { get; set; }
}
[HttpGet("/api/country-details")]
public IActionResult CountryDetailGet(CountryDialCodeFields BodyData)
{
var CountryDataSet22 = CountryCodeDbContext.Countrydetails.Where( x => (BodyData.countryCode != null ? x.Countrycode == BodyData.countryCode) &&
(BodyData.countryName != null ? x.Countryname == BodyData.countryName) &&
(BodyData.currencyCode != null ? x.Currencycode == BodyData.currencyCode) &&
(BodyData.currencyCode != null ? x.Dialcode == BodyData.dialCode));
}
Straightforward way:
Or using extension: