Can't resolve DbContext.Set
I'm trying to do some testing of Rider on linux. I have a data project in which I installed the Microsoft.EntityFrameworkCore library along with the Relational, SqlServer and Tools ones too. In my repository it can't recognize my DbContext.Set method. I get an error - Cannot resolve symbol 'Set' and on build, DbClass.cs(50, 26): [CS1061] 'IWebDbContext' does not contain a definition for 'Set' and no accessible extension method 'Set' accepting a first argument of type 'IWebDbContext' could be found (are you missing a using directive or an assembly reference?)
If I ctrl+click on the DbContext to view it's code, I clearly see two Set methods defined. Is there another nuget package I need to reference to get this functionality?
Please sign in to leave a comment.
I tested this on windows with the same code and after simply adding the Microsoft.EntityFrameworkCore reference, dbcontext.Set was recognized without error.
Hello Gswartz,
Thank you for reaching Rider Forum.
Could you please let me know the following:
1. Rider version;
2. Linux version;
3. Code snippet to reproduce the issue.
Thank you in advance!
1. 2023.1
2. KDE neon 5.27 Release 22.04
public interface IBaseRepository<T> where T : class
{
Task<T> AddAsync(T entity);
Task DeleteAsync(T entity);
Task DeleteManyAsync(Expression<Func<T, bool>> filter);
Task<IEnumerable<T>> GetAllAsync();
Task<T> GetByIdAsync(int id);
Task<IEnumerable<T>> GetManyAsync(Expression<Func<T, bool>> filter = null,
Func<IQueryable<T>, IOrderedQueryable<T>> orderBy = null,
int? top = null,
int? skip = null,
params string[] includeProperties);
}
public class BaseRepository<T> : IBaseRepository<T> where T : class
{
protected readonly IWebDbContext _context;
protected readonly DbSet<T> _dbSet;
public BaseRepository(IWebDbContext context)
{
_context = context;
_dbSet = context.Set<T>();
}
public async Task<T> AddAsync(T entity)
{
await _dbSet.AddAsync(entity);
return entity;
}
public Task DeleteAsync(T entity)
{
_dbSet.Remove(entity);
return Task.CompletedTask;
}
public Task DeleteManyAsync(Expression<Func<T, bool>> filter)
{
var entities = _dbSet.Where(filter);
_dbSet.RemoveRange(entities);
return Task.CompletedTask;
}
public async Task<IEnumerable<T>> GetAllAsync()
{
return await _dbSet.ToListAsync();
}
public async Task<T> GetByIdAsync(int id)
{
return await _dbSet.FindAsync(id);
}
public async Task<IEnumerable<T>> GetManyAsync(
Expression<Func<T, bool>> filter = null,
Func<IQueryable<T>, IOrderedQueryable<T>> orderBy = null,
int? top = null,
int? skip = null,
params string[] includeProperties)
{
IQueryable<T> query = _dbSet;
if (filter != null)
{
query = query.Where(filter);
}
if (includeProperties.Length > 0)
{
query = includeProperties.Aggregate(query, (theQuery, theInclude) => theQuery.Include(theInclude));
}
if (orderBy != null)
{
query = orderBy(query);
}
if (skip.HasValue)
{
query = query.Skip(skip.Value);
}
if (top.HasValue)
{
query = query.Take(top.Value);
}
return await query.ToListAsync();
}
}
Hey Gswartz,
I could not reproduce the issue with the piece of code you sent. I have IWebDbContext not being resolved on 3 machines with different Operation Systems.
Then, to continue the investigation, could you please generate logs from both machines using Help > Collect Logs? This way I could see the differences in the Riders' setup. Pleas e upload the logs to our shared storage at https://uploads.jetbrains.com and provide me with the ID.
Thank you in advance!
Sorry for the delay. I've been buried on other things. The upload id is 2023_06_30_22RNwqpSMf7NrhnC5aeFrg. Thanks.
Hello Gswartz,
Thank you for the update.
We need more details to understand the root cause:
Thank you in advance. Looking forward to hearing from you soon.
If I try to run dotnet build within the terminal in rider it also gives me the error...
/home/gswartz/RiderProjects/DbTest/WebBLL/Services/DbClass.cs(50,26): error CS1061: 'IWebDbContext' does not contain a definition for 'Set' and no accessible extension method 'Set' accepting a first argument of type 'IWebDbContext' could be found (are you missing a using directive or an assembly reference?) [/home/gswartz/RiderProjects/DbTest/WebBLL/WebBLL.csproj]
Thanks Gswartz,
Could you please install Microsoft.EntityFrameworkCore NuGet in your Linux Rider installation? If you already did, please remove it from the project using this button:
And install again.
Looking forward to hearing from you.
I did already have it installed but after reinstalling I unfortunately still have the same error.
Hello Gswartz,
Thank you for the update.
Unfortunately, since the code sample is not building with the dotnet command itself and NuGet re-installation has not helped the issue, I would suggest you creating a request to dotnet/efcore, so they could check the issue deeper.
Thank you for understanding. Have a nice day!