Generic Repository, CreateObjectSet() Method

前端 未结 1 1612
伪装坚强ぢ
伪装坚强ぢ 2021-01-19 01:46

I was trying to implement a generic repository, and I have this right now:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Da         


        
相关标签:
1条回答
  • 2021-01-19 02:28

    You will need to change your method to look like this:

    public GenericRepository(ApplicationDbContext _entities)
    {
        entities = _entities;
        _objectSet = entities.Set<T>(); //This line changed.
    }
    

    This should have the function that you desire. The .Set<T>() is the generic method that returns the DbSet of the type used.

    UPDATE:

    With the change in return type you will need to change your _objectSet type as well.

    DbSet<T> _objectSet;
    
    0 讨论(0)
提交回复
热议问题