views:

286

answers:

2

Hey

I'm trying to do a nested lambda expression like to following:

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

but i get the 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 relation to spokenlanguage:

[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?

+1  A: 

The issue is definitely an issue with "Linq to SQL" and most likely the association.

Here are a couple suggestions:

  • You don't mention if you use the [AssociationAttribute] set on your child table, you will need it if it's not present.
  • You will probably have to use DataLoadOptions on your DataContext, so the child table is loaded when the parent table is queried.
  • In the set method of an Entity< T> property, I would use _SpokenLanguage.Assign(value) instead of _SpokenLanguage = value
Jonathan.Peppers
A: 

I have 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; }
    }

On the datacontext this is added:

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

Any further ideas? Mayby it just me misunderstood some fundamental stuff??

Lehto
Are you trying to set up associations manually?
Victor