[script_id] не будет распознан как шаблон из PostViewModel. Я не знаю, разрешено ли в этих фигурных скобках использовать оператор IF.
Код: Выделить всё
//A class inside the Models Folder
public class PostViewModel
{
public string script_id { get; set; }
public string script_code { get; set; }
public string status { get; set; }
}
//A class inside Models Folder
public class ScriptConstants
{
public const string script_id = "script_id";
public const string script_code = "script_code";
public const string status = "status";
}
//Part of the Home controller accessing an oracle database and will read the row
while (reader.Read())
{
var Scripts = new PostViewModel
{
If (ColumnExists(reader, ScriptConstants.script_id) == true)
{
script_id = reader(ScriptConstants.script_id)
}
};
}
private bool ColumnExists(IDataReader reader, string columnName)
{
for (int i = 0; i < reader.FieldCount; i++)
{
if (reader.GetName(i).Equals(columnName, StringComparison.InvariantCultureIgnoreCase))
{
return true;
}
}
return false;
}
Подробнее здесь: https://stackoverflow.com/questions/792 ... on-c-sharp
Мобильная версия