Open
Description
Library name and version
- Kros.KORM 3.0
Description
Query fails when using generic method with generic type constrait for interface like where T : IInterface
with readonly members. Where this generic type is used as generic type of Database.Query<T>
and Where()
method is used.
Steps To Reproduce
- Create generic method with query in it and interface must containts field Id
private IResource GetResourceById<TResource>(string tableName, int id) where TResource : IResource
=> _database.Query<TResource>()
.From(tableName)
.FirstOrDefault(x => (x.Id == id));
- Call this method, with correct generic type, implemeting mentioned interfaca
GetResourceById<MyResource>(mytable, id);
- Call fails on NullReferenceException.
Expected behavior
Correctly return selected item byt id, without throwing an exception.
Actual behavior
Cause of problem is readonly field Id
on interface.
When KORM is creating TableInfo
in ConventionModelMapper.CreateTableInfo()
for where clausule. It is reading only writable properties from given type. Type in this case is interface from constraint, instead of correct generic type given for query.
KORM in this point should "know" it is creating only where clausule and properties doesn't have to be writable.