Nested lambda expressions and string cultures

I am trying to make a nested lambda expression like this:

textLocalizationTable.Where(
  z => z.SpokenLanguage.Any(
    x => x.FromCulture == "en-GB")
  ).ToList();

but I get an error:

Member access 'System.String FromCulture' of 
'DomainModel.Entities.SpokenLanguage' not legal on type
'System.Data.Linq.EntitySet`1[DomainModel.Entities.SpokenLanguage].

TextLocalization has this to do with spoken language:

[Association(OtherKey = "LocalizationID", ThisKey = "LocalizationID", Storage = "_SpokenLanguage")]
private EntitySet<SpokenLanguage> _SpokenLanguage = new EntitySet<SpokenLanguage>();
public EntitySet<SpokenLanguage> SpokenLanguage
{
     set { _SpokenLanguage = value; }
     get { return _SpokenLanguage; }
}

Any idea what is wrong?


I tried your suggestion with the same error.

Spokenlanguage now has this association:

    internal EntityRef<TextLocalization> _TextLocalization;
    [Association(ThisKey = "LocalizationID", OtherKey = "LocalizationID", Storage = "_TextLocalization")]
    public TextLocalization TextLocalization
    {
        get { return _TextLocalization.Entity; }
        internal set { _TextLocalization.Entity = value; LocalizationID = value.LocalizationID; }
    }

In the datacontext this is added:

        DataLoadOptions dlo = new DataLoadOptions();
        dlo.LoadWith<TextLocalization>(text => text.SpokenLanguage);
        dc.LoadOptions = dlo;

Any other ideas? Maibi, is it just that some fundamental things misunderstood me?

+3
source share
1 answer

The problem, of course, is related to "Linq to SQL" and, most likely, to the association.

Here are some suggestions:

  • , [AssociationAttribute] , , .
  • , , DataLoadOptions DataContext, .
  • Entity <T> , _SpokenLanguage.Assign() _SpokenLanguage =
+1

Source: https://habr.com/ru/post/1737183/


All Articles