By default, when opening forms in the LookUp displays the entire list of objects from which to select. However, often the situation arises when a complete list is impossible.

Therefore, the question arises: how to limit the output if you picked up on LookUp?

Example 1

Given the following diagram.

When you create a new object of type Кредит need to choose Клиента to which the loan. For example, that a restriction to lend only to persons resident in the city of Perm (i.e. if Прописка Client contains a “Perm”).

To build a restriction using LINQProvider:

var ds = (SQLDataService) DataServiceProvider.DataService;
IQueryable<Клиент> limit = ds.Query<Клиент>(Клиент.Views.КлиентL).Where(klient => klient.Прописка.Contains("Perm"));

Then get a restraining function using the class LinqToLcs:

Function onlyPermKlients = LinqToLcs.GetLcs(limit.Expression, Клиент.Views.КлиентL).LimitFunction;

Restrict LookUp field by selecting LimitFunction:

ctrlКлиент.LimitFunction = onlyPermKlients;

As a result, when you open lookup-shape Clients this page displays only Clients that have the word “Perm” in the field “Registration”.

Example 2

The more difficult task: let the residence, is in a class thus, it is necessary to impose restrictions on master:

Additionally, you want to show only working КредитныхИнспекторов.

1.Build constraints by filling a LINQ provider:

var ds = (SQLDataService) DataServiceProvider.DataService;
IQueryable<Клиент> limit1 = ds.Query<Клиент>(Клиент.Views.КлиентL).Where(klient => klient.Прописка.Город == "Perm");
IQueryable<КредитныйИнспектор> limit2 = ds.Query<КредитныйИнспектор>(КредитныйИнспектор.Views.КредитныйИнспекторL).Where(insp => insp.Работает);

2.To restrictive feature:

Function onlyPermKlients = LinqToLcs.GetLcs(limit1.Expression, Клиент.Views.КлиентL).LimitFunction;
Function onlyWorkingInspektors = LinqToLcs.GetLcs(limit2.Expression, КредитныйИнспектор.Views.КредитныйИнспекторL).LimitFunction;

3.The limitations on LookUpы for Customers and Inspectors:

ctrlКлиент.LimitFunction = onlyPermKlients;
ctrlКредитныйИнспектор.LimitFunction = onlyWorkingInspektors;