Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Generic query not working correctly in generic method with generic type constraint for interface with readonly fields and where clausule #56

Open
wosciatko opened this issue Jan 23, 2020 · 0 comments
Labels
bug Something isn't working

Comments

@wosciatko
Copy link

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

  1. 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));
  1. Call this method, with correct generic type, implemeting mentioned interfaca
GetResourceById<MyResource>(mytable, id);
  1. 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.

@wosciatko wosciatko added the bug Something isn't working label Jan 23, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant