missing logic to the LINQ query which does not work

Rock Hitman 46 Reputation points
2021-12-24T08:54:58.617+00:00

public IHttpActionResult InsuranceLimit(InsuranceLimitDTO IL)
{
var result = from b in db.InsuranceTransferAcc
where b.UserId == IL.UserId
select b.CreatedDate;
}

This above query (result ) is returning me empty. Not understanding what I am missing in this query. It should return me the CreatedDate coloumn value for that UserId passed.

InsuranceTransferAcc is actual sql table where multiple columns (fields) are present. InsuranceLimitDTO is my schema where my input parameters are cOming from a POST API call.... I am trying to first check the passed input parameter value (IL.UserId) from the table InsuranceTransferAcc matches (b.UserId)...if so I need that related CreatedDate value in output (b.CreatedDate ). Hope my question makes sense

SQL Server
SQL Server
A family of Microsoft relational database management and analysis systems for e-commerce, line-of-business, and data warehousing solutions.
12,700 questions
C#
C#
An object-oriented and type-safe programming language that has its roots in the C family of languages and includes support for component-oriented programming.
10,237 questions
Transact-SQL
Transact-SQL
A Microsoft extension to the ANSI SQL language that includes procedural programming, local variables, and various support functions.
4,552 questions
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. Karen Payne MVP 35,036 Reputation points
    2021-12-24T11:35:47.503+00:00

    You need to have a return statement since the current code never returns anything. Try return Ok(result); or if there truly are no results return NotFound(); and if that is the case you need to set a breakpoint, examine IL.UserId.