Skip to content

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

Open
@wosciatko

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

  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.

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions