Howto FilterOn()

Posts   
 
    
neil.allen
User
Posts: 2
Joined: 03-Jun-2020
# Posted on: 03-Jun-2020 15:14:54   

Given the code below, what do I need at XXXX to have LanguageID == CustomerEntity.BusinessLanguageID [from this bit -> Prefetch<CustomerEntity>(cn => cn.Customer] - they're both Guids and so is languageId

I've tried

td.Country.Customer.First().BusinessCountryId

which resulted in a 'No coercion operator is defined between types '.EntityClasses.CustomerEntity' and 'System.Guid'.' error.

Help!, Many thanks for looking. N


            using (DataAccessAdapter adapter = new DataAccessAdapter())
            {
                LinqMetaData metaData = new LinqMetaData(adapter);

                var contracts = (
                    from cn in metaData.Contract
                    where cn.ContractId == contractId
                    select cn)
                        .WithPath(
                            pt1 => pt1
                            // store
                            .Prefetch<StoreEntity>(cn => cn.Store)
                                .Include(s => s.StoreName)
                            // customer 
                            // only returning those fields required along with translated country name
                            .Prefetch<CustomerEntity>(cn => cn.Customer)
                                .Include(cs => cs.CustomerId, cs => cs.Surname, cs => cs.Forename, cs => cs.Address, cs => cs.City, cs => cs.Zip, cs => cs.IdType, cs => cs.IdNumber, cs => cs.IdExpiryDate, cs => cs.TelephoneNumber, cs => cs.Type,
                                    cs => cs.BusinessName, cs => cs.BusinessAddress, cs => cs.BusinessCity, cs => cs.BusinessZip, cs => cs.BusinessUser, cs => cs.BusinessVatnumber, cs => cs.EmailAddress, cs => cs.IsGovernmentUser)
                                .SubPath(pt2 => pt2.Prefetch<CountryEntity>(cs => cs.Country)
                                    .Include(co => co.CountryId, co => co.CountryName)
                                    .SubPath(pt3 => pt3.Prefetch<TranslationDictionaryEntity>(co => co.TranslationDictionary)
                                        .Include(td => td.TranslatedText)
                                        .FilterOn(td => td.LanguageId == languageId && td.ColumnName == "COUNTRYNAME")
                                            )
                                        )
                                 .SubPath(pt2 => pt2.Prefetch<CountryEntity>(cs => cs.BusinessCountry)
                                    .Include(co => co.CountryId, co => co.CountryName)
                                    .SubPath(pt3 => pt3.Prefetch<TranslationDictionaryEntity>(co => co.TranslationDictionary)
                                        .Include(td => td.TranslatedText)
                                        .FilterOn(td => td.LanguageId == XXXXX && td.ColumnName == "COUNTRYNAME")
                                            )
                                        )

-- there was a missing part to the FilterOn lambda which I have now fixed.

Walaa avatar
Walaa
Support Team
Posts: 14950
Joined: 21-Aug-2005
# Posted on: 04-Jun-2020 05:22:34   

This test worked for me on Northwind.

var q = (from c in metaData.Customer
         select c)
        .WithPath(p => p
        .Prefetch<OrderEntity>(c => c.Orders)
        .SubPath(op => op.Prefetch<EmployeeEntity>(o => o.Employee)
        .FilterOn(e => e.Orders.First().Customer.Country == e.Country)));
neil.allen
User
Posts: 2
Joined: 03-Jun-2020
# Posted on: 04-Jun-2020 12:03:31   

The info from WALAA helped me with this, thanks.