I am developing a multi-language site with c#. In my database, my columns continue as en_Title, en_Content. I have a function to get the news, I am sending the active language as a parameter to this function.
Function
public static List<Haberler> GetHaber(string lang)
{
using (BIRLIKB2BEntities db = new BIRLIKB2BEntities())
{
var Haber = db.Database.SqlQuery<Haberler>($"SELECT ID, {lang}_Baslik, {lang}_KisaAciklama, {lang}_Icerik FROM Haberler").ToList();
return Haber;
}
}
I want to pull only the language columns according to the language code that comes here. But I guess entity framework is giving error
Error:
The data reader is incompatible with the specified 'BIRLIKB2BModel.Haberler'. A member of the type, 'Baslik', does not have a corresponding column in the data reader with the same name.
The result of these processes is the output I expected. just reading the columns I send in the function. Is there an alternative way to solve this? can you help?
Table
ID|tr_Baslik|tr_Aciklama|tr_Icerik|en_Baslik|en_Aciklama|en_Icerik
1 | Turkey | Turkey | Turkey |English |English |English|