TEntity - это Generic BaseClass, и есть два класса, производных от BaseClass LocationEntity и ZoneEntity.
Ниже GetById() имеет контекст LocationEntity, но response.Resource возвращает объект ZoneEntity.
public async Task<TEntity> GetById(string id)
{
TEntity readObj = null;
try
{
var response = await client.ReadDocumentAsync(UriFactory.CreateDocumentUri(dbName, collectionName, id),
requestOptions);
readObj = (TEntity) (dynamic) response.Resource; // it's ignoring the properties which does not match with TEntity (LocationEntity)
}
catch (Exception ex)
{
throw ex;
}
return readObj;
}
Как выполнить строгую проверку типов при преобразовании DocumentDB Document в TEntity?
Я хочу создать исключение или что-то в этом роде, когда response.Resource не относится к типу LocationEntity.