Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Am I misunderstanding the usage? #22

Closed
ByZhouhang opened this issue Apr 20, 2022 · 3 comments
Closed

Am I misunderstanding the usage? #22

ByZhouhang opened this issue Apr 20, 2022 · 3 comments

Comments

@ByZhouhang
Copy link

public class User:
    {
        public string FirstName { get; set; }
        public string LastName { get; set; }

     [Projectable] 
     public string FullName => LastName + " / " + FirstName;

    }

// want  wirte like this  
_userRepository.Where(t => t.FullName .Contains("CC")).First()    //Translation of member 'FullName' on entity type 'User' failed

_userRepository.Select(t => t.FullName).First()  //will cause  query for all fields  (not   LastName FirstName  two filed)
@koenbeuk
Copy link
Owner

koenbeuk commented Apr 20, 2022

You'll have to enable Projectables within your DbContext:

e.g. in case of DI:

services.AddDbContext<ApplicationDbContext>(options => {
      options
          .UseSqlite(dbConnection)
          .UseProjectables() // Add this line
  })

@ByZhouhang
Copy link
Author

You'll have to enable Projectables within your DbContext:

e.g. in case of DI:

services.AddDbContext<ApplicationDbContext>(options => {
      options
          .UseSqlite(dbConnection)
          .UseProjectables() // Add this line
  })

thanks,The reason for the difference is ?
1、[Projectable] public string FullName => LastName + " / " + FirstName;
2、[Projectable] public string FullName => => $"{LastName} / {FirstName}"
_userRepository.Where(t => t.FullName .Contains("CC")).First() // 2. will error can not translate string.formate

@koenbeuk
Copy link
Owner

@ByZhouhang

EF Core does not support string interpolation (String.Format), this library does not change that fact, see: dotnet/efcore#6532 (comment)

@koenbeuk koenbeuk closed this as completed Aug 3, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants