M# Tutorials

Learn to build .NET applications with M#. Our step-by-step tutorials will get you up-to-speed rapidly.
If you already know ASP.NET and C#, you can master M# in a week or two.

Database.GetList()

This method within M# Data access repository returns a list of records

IEnumerable<T>

for a specific Entity

T

. M# gives you the possibility to get a list of data from the database and to apply filters. We will see at the end of this lesson how to correctly write filters that will be correctly translated into SQL.

Overloads

Database.GetList()


All the overloads of this method require an argument of Type and return an

IEnumerable<Entity>

.

Overload 1


This overload allows you to pass an array of Criterion.
Example:

Criterion is M#’s internal class used to provide parameters, comparators and respective values to be searched in the database.

Overload 2


This overload allows you to pass an existing QueryOption, for example PagingQueryOption, or to pass a new one.
Example:

Overload 3


This overload allows you to pass a list of Guid.
Example:

Overload 4


This overload allows you to pass a list of Criterion and an array of QueryOption.
Example:

Database.GetList<T>()


Except the first one, all the overloads are similar to ones for the function GetList().

Overload 1


This overload will returns all employees.
Example:

Overload 2

Overload 3

Overload 4

Overload 5

Overload 6

Overload 7

Overload 8

Overload 9

Important: Always split complex criteria by specifying it using "Where" Linq extension method. This is because, a simple criterion is translated into SQL query which runs in the database context and also enables caching of result set. Specifying complex criteria or calculated properties directly into method lambda expression will result in fetching all the results in the memory and then performing the criteria query. You should also avoid using “||” conditional operator in lambda expression and instead write separate data queries using “Database.Get()” and then combine the all the resultant sets. This also helps to boost performance and aids data caching. Performance related quires are explained in more detail in tutorial Data Queries