Reputation: 1040
I have this method on class:
member this.GetDbSet<'TEntity, 'TDTO, 'TKey when 'TKey :> IEquatable<'TKey> and 'TEntity :> IEntity<'TKey> and 'TEntity : not struct and 'TDTO :> IDTO<'TKey> and 'TEntity : equality and 'TEntity : null and 'TDTO : equality and 'TDTO : null and 'TKey : equality>(repository : BaseRepository<'TEntity, 'TDTO, 'TKey>) =
repository.DbSetFuncGetter().Invoke(uow.Context())
but when I build the project I get this error
This code is not sufficiently generic. The type variable 'TEntity when 'TEntity :> IEntity<'TKey> and 'TEntity : not struct and 'TEntity : equality and 'TEntity : null and 'TKey :> IEquatable<'TKey> and 'TKey : equality could not be generalized because it would escape its scope.
But all constraints are there. Am I missing something?
Edit:
If you need more code:
this is the open source project
Upvotes: 3
Views: 211
Reputation: 1040
I don't know why that error message was displayed for my code but I found workaround and I committed on GitHub project. You can check the diff on this file because it's easier to read than describe it.
The link contains the diff that solves the question but I'll explain that in the next lines.
I solved it with a workaround, I don't know why it was displaying.
On the repository class (the class of repository in the question, not the class of the method) has these members:
let mutable dbSetFunc : Func<DbContext, DbSet<'TEntity>> = null
member this.DbSetFunc
with set (value) = dbSetFunc <- value
member this.DbSetFuncGetter() = dbSetFunc
but they generated the error, I found it trying commenting them and I changed them to these
[<DefaultValue>] val mutable dbSetFunc : Func<DbContext, DbSet<'TEntity>>
member this.DbSetFunc
with set (value) = this.dbSetFunc <- value
member internal this.DbSetFuncGetter() = this.dbSetFunc
And I can't explain why this solves the error, at least I hope this helps.
The method in the question remains the same.
Upvotes: 2