需要检查 If body data Null 和如果 Null 归档,不需要检查特定的 WHERE 子句。如何使用 NULL 检查添加多个 WHERE 和 OR 子句?在CountryDialCodeFields
中,某些字段有时可能为空。
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));
}