I have following objects:
public class City
{
public int CityId { get; set; }
public string Name { get; set; }
public virtual ICollection<CityTranslation> CityTranslations { get; set; }
}
public class CityTranslation
{
public int CityId { get; set; }
public string LanguageCode { get; set; }
public string Translation { get; set; }
public virtual City City { get; set; }
}
City table contain default language value in Name field other translations are in CityTranslation table.
I am having problem to get value by language from this.
I am trying to execute following:
public virtual IEnumerable<City> GetAllByLanguage(string language)
{
if (language != "en")
{
var data = from c in context.Cities
join t in context.CityTranslations
on c.CityId equals t.CityId
&& t.LanguageCode == language
select c;
}
else
{
return dbSet.ToList();
}
}
But I am gettings compile error.
Operator '&&' cannot be applied to operands of type 'int' and 'bool'
plus some casting errors.
What should I do to get value from translation table?
t.CityIdisint,t.LanguageCode == languagereturnsboolean. And&&is logical AND operator. You can't use it wthintandbool.where t.LanguageCode == language? You can also include theWHEREclause in lambda syntax in the reference to the table you're joining on e.gjoin t in context.CityTranslations.Where(x => x.LanguageCode == language) on c.CityId equals t.CityIdvar data = from c in context.Cities join t in context.CityTranslations.Where(x => x.LanguageCode == language) on c.CityId equals t.CityId select c;but I am getting casting error.