Class Mapping Error: 'T' must be a non-abstract type with a public parameterless constructor

前端 未结 3 986
青春惊慌失措
青春惊慌失措 2020-12-01 03:06

While mapping class i am getting error \'T\' must be a non-abstract type with a public parameterless constructor in order to use it as parameter \'T\' in the generic type or

3条回答
  •  醉酒成梦
    2020-12-01 04:03

    The constraints must apply to every type in the chain; hence you need:

    public abstract class SqlReaderBase : ConnectionProvider where T : new()
    

    Without this, you can't satisfy the constraint for T in:

    protected abstract MapperBase GetMapper();
    

    or

    MapperBase mapper = GetMapper();
    

    since MapperBase<> is only usable when T has : new()

提交回复
热议问题