Sample Database
The Query Galery is based on the sample database of:
The assumption is that logic is needed for Controller to return either a single Film model or a List if more than one record results from the query.
It is also assumed a DbSet() of Films has been set up.
Extract One Record by Primary Key
With SQL the query would be:
The View would be set up to receive a single entity that matched the model. Assume an id value is sent as a routing parameter.
Use the Find() method of DbSet :
LINQ Query Syntax:
LINQ Method Syntax:
Extract Multiple Records (no filter)
The View for these examples would be set up to receive a List of entities.
With SQL the query would be:
Use the ToList() method of DbSet :
LINQ Query Syntax:
Extract Multiple Records (with WHERE filter)
The View for these examples would be set up to receive a List of entities.
With SQL the query would be:
LINQ Query Syntax:
LINQ Method Syntax:
Extract Multiple Records (with Multiple WHERE filters)
The View for these examples would be set up to receive a List of entities.
With SQL the query would be:
LINQ Query Syntax:
LINQ Method Syntax:
Extract Mutiple Record With a Contains Query
With SQL the query would be:
The View for these examples would be set up to receive a List of entities.
LINQ Query Syntax:
LINQ Method Syntax: