1

I have the following interface signature that I want to use for a more efficient bulk update using EF Core 8.0.6

using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Query;
using System.Linq.Expressions;

namespace IRepositories
{
    Task<int> UpdateDirectAsync(Expression<Func<T, bool>> filter,
                 Func<SetPropertyCalls<T>, 
                 SetPropertyCalls<T>> setPropertyCalls);
    }
}

But I am getting the following error:

The type or namespace name 'SetPropertyCalls<>' could not be found (are you missing a using directive or an assembly reference?)

How can I resolve this?

11
  • Make sure that the Microsoft.EntityFrameworkCore.Relational package is referenced. Commented Oct 19 at 18:19
  • You have a namespace - but you're lacking a public interface ISomethingOrAnother...... in your code ..... Commented Oct 19 at 18:28
  • 2
    Not really sure what you're saying. Why do you need a separate "repository", the DbContext is already a respository? Just do await myDb.SomeTable.Where(whatever).ExecuteUpdateAsync(x => x.SetProperty(whatever what does your generic method offer that ExecuteUpdateAsync does not? Commented Oct 19 at 20:03
  • 1
    @Josh, when it comes to reusing queries, I typically just use extension methods. Commented Oct 20 at 9:52
  • 1
    "he reason some of us still do the repository pattern is to enable us to write the query once and reuse it everywhere else" : And yet, that is exactly not what you are writing. because such a method needs Expression<Func<T>> and Func<T> declarations to cater to differences in consumer needs. A Repository can standardize common behavior by leveraging IQueryable<T>. You are trying to scratch an itch at the thought of writing similar, dead simple query statements multiple times, but replacing it with writing one complex beast that still needs multiple complex parameters. Commented Oct 20 at 20:12

1 Answer 1

4

I later discovered that the basic EFCore does not contain the SetPropertyCalls method. I needed to install Microsoft.EntityFrameworkCore.Relational package which contains the Query namespace where the SetPropertyCalls method lives.

So adding the following

<PackageReference Include="Microsoft.EntityFrameworkCore.Relational" Version="8.0.0" />

in the .csproj and then adding the following using statement

using Microsoft.EntityFrameworkCore.Query;

finally resolved the issue.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.