Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/joomla/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 嵌套lambda表达式和字符串区域性_C#_Linq To Sql_Lambda - Fatal编程技术网

C# 嵌套lambda表达式和字符串区域性

C# 嵌套lambda表达式和字符串区域性,c#,linq-to-sql,lambda,C#,Linq To Sql,Lambda,我正在尝试执行嵌套lambda表达式,如下所示: textLocalizationTable.Where( z => z.SpokenLanguage.Any( x => x.FromCulture == "en-GB") ).ToList(); 但我得到了一个错误: Member access 'System.String FromCulture' of 'DomainModel.Entities.SpokenLanguage' not legal on typ

我正在尝试执行嵌套lambda表达式,如下所示:

textLocalizationTable.Where(
  z => z.SpokenLanguage.Any(
    x => x.FromCulture == "en-GB")
  ).ToList();
但我得到了一个错误:

Member access 'System.String FromCulture' of 
'DomainModel.Entities.SpokenLanguage' not legal on type
'System.Data.Linq.EntitySet`1[DomainModel.Entities.SpokenLanguage].
TextLocalization与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; }
}
[关联(OtherKey=“LocalizationID”,ThisKey=“LocalizationID”,Storage=“\u SpokenLanguage”)]
私有EntitySet _SpokenLanguage=新EntitySet();
公共实体集SpokenLanguage
{
设置{u SpokenLanguage=value;}
获取{return\u SpokenLanguage;}
}
你知道怎么了吗


我试过你的建议,但也犯了同样的错误

Spokenlanguage现在有以下关联:

    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; }
    }
internalentityref\u text本地化;
[关联(ThisKey=“LocalizationID”,OtherKey=“LocalizationID”,Storage=“\u TextLocalization”)]
公共文本本地化文本本地化
{
获取{return\u TextLocalization.Entity;}
内部集合{u TextLocalization.Entity=value;LocalizationID=value.LocalizationID;}
}
在datacontext上添加以下内容:

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

还有其他想法吗?也许只是我误解了一些基本的东西???

这个问题肯定是“Linq到SQL”的问题,很可能是关联的问题

以下是一些建议:

  • 你没有提到你是否使用了 [AssociationAttribute]设置在您的 子表,如果它不存在,您将需要它
  • 您可能必须在DataContext上使用DataLoadOptions,以便在查询父表时加载子表
  • 在实体属性的set方法中,我将使用_SpokenLanguage.Assign(value)而不是_SpokenLanguage=value

这实际上是一个从LINQ到SQL的问题吗?这可能与我经常使用的嵌套lambda本身无关……如果您尝试“textLocalizationTable.Where(z=>z.SpokenLanguage.Where(x=>x.FromCulture==“en GB”).Count()>0.ToList();”?您能显示
SpokenLanguage
类,至少是相关属性吗?一点主题,但是尝试将
SpokenLanguage
属性重命名为
SpokenLanguages
,因为这样可以更好地描述它是什么;多个
SpokenLanguage
对象的集合。与Kurresmack代码相同的错误。spokenLanguage FromCulture属性:[Table(Name=“ep_text_spokenLanguage”)]公共类spokenLanguage{[Column]公共字符串FromCulture{get;set;}