Hi.
Do you know how to make this work for properties of type EntityReference?
I added a property to the Account model which is a Entity reference that reffers another account.
property:
[AttributeLogicalName("mot_referedaccount")]
public EntityReference mot_referedaccount
{
get => this.GetAttributeValue(nameof (mot_referedaccount));
set
{
this.OnPropertyChanging(nameof (mot_referedaccount));
this.SetAttributeValue(nameof (mot_referedaccount), (object) value);
this.OnPropertyChanged(nameof (mot_referedaccount));
}
}
Then I added this test:
[TestMethod]
public void EntityFilter_EntityReference()
{
// Create source entity list
var accounts = GetAccountList();
// Define queries to be appled on source
var queryExpression = new QueryExpression();
queryExpression.Criteria.AddCondition("mot_referedaccount", ConditionOperator.Equal, new EntityReference(Account.EntityLogicalName, accounts[1].Id));
// Apply filters on entity list
IEntityFilter<Account> entityFilter = new EntityFilter<Account>();
var filteredResults = entityFilter.FilterBy(accounts, queryExpression);
Assert.AreEqual(1, filteredResults.Count);
}
GetAccountList2() looks like this:
private List GetAccountList2()
{
var accountFaker = new Faker()
.RuleFor(a => a.accountid, f => f.Random.Guid())
.RuleFor(a => a.name, f => $"{f.Company.CompanyName()} {f.Company.CompanySuffix()}")
.RuleFor(a => a.accountnumber, f => String.Join("", f.Random.Digits(5)))
.RuleFor(a => a.createdon, f => f.Date.Past(1))
.RuleFor(a => a.telephone1, f => f.Phone.PhoneNumber())
.RuleFor(a => a.emailaddress1, f => f.Internet.Email())
.RuleFor(a => a.fax, f => f.Phone.PhoneNumber())
.RuleFor(a => a.donotemail, f => f.Random.Bool())
.RuleFor(a => a.donotfax, f => f.Random.Bool())
.RuleFor(a => a.donotphone, f => f.Random.Bool())
.RuleFor(a => a.preferredcontactmethodcode, f => f.PickRandom<Account_PreferredContactMethodCode>());
var list = accountFaker.Generate(2).ToArray();
list[0].mot_referedaccount = new EntityReference(Account.EntityLogicalName, list[1].Id);
return list.ToList();
}
The entity filter will always return 0 accounts. Any idea why?