I know this is far from optimal, but here goes: In our team, we develop against the same development database, which sometimes gives us some trouble. Most of our trouble comes from "Invalid column name" errors, which happens when someone else modifies the database entities, which means SQL statements such as SELECT Id, Name FROM TableName fails if Name no longer exists.
Obviously this is not optimal, and we are moving towards having our own local environments, but this is what we have at the moment. I know the error comes from the database, but it would be really nice, if it was possible to have a fallback of some kind. Something like:
public class Person
{
public int Id { get; set; }
public string Name { get; set; }
}
public async Task DoStuff()
{
var people = new List<Person>();
try
{
people = await _dbContext.Persons.Select(x => new Person
{
Id = x.Id,
Name = x.Name
})
.ToListAsync();
}
catch (Exception e)
{
if(e.Message.Contains("Invalid column name 'Name'")
{
people = await _dbContext.Persons.Select(x => new Person
{
Id = x.Id,
Name = default
})
.ToListAsync();
}
}
}
Get the point? If the database cannot find the column Name anymore, it should still SELECT stuff, but set Name to the default value (or null). Is that something Entity Framework can do? I know that I might potentially experience more issues, but 99/100 times someone has made a change, this is the culprit.