C# Simple query Join between to entities 1..N

Havin to entities query the first one and filter by values on the first one and second one.

QueryExpression query = new QueryExpression
	EntityName = "h_licence",
	ColumnSet = new ColumnSet("h_regno", "h_rootregnumber", "h_revisionnumber", "h_libraryname"),

query.Criteria.AddCondition("h_licencestatus", ConditionOperator.Equal, 919780001);
query.Criteria.AddCondition("h_licencetype", ConditionOperator.In, 919780002, 953210002, 953210001, 919780001);
query.Criteria.AddCondition("h_substatus", ConditionOperator.NotIn, 4); //Exclude NFA
query.Criteria.AddCondition("statecode", ConditionOperator.Equal, "Active");

query.LinkEntities.Add(new LinkEntity("h_licence","h_licenceprofile","h_licenceprofileid","h_licenceprofileid",JoinOperator.Inner));
query.LinkEntities[0].LinkCriteria.AddCondition("h_enforcementriskcategory", ConditionOperator.Equal, os.Value);

return se.RetrieveMultiple(query);


Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s