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

DbFunctions: instance functions on entities #9811

Open
divega opened this issue Sep 13, 2017 · 5 comments
Open

DbFunctions: instance functions on entities #9811

divega opened this issue Sep 13, 2017 · 5 comments

Comments

@divega
Copy link
Contributor

divega commented Sep 13, 2017

Consider the scenario originally described at #9213 (comment) (about why instance functions on DbContext can be compelling):

db.Posts.Where(p => db.PostReadCount(p.Id) > 5);

It could actually be even more compelling to be able to do this:

db.Posts.Where(p => p.ReadCount() > 5);

This could work for instance methods, computed properties or even extension method defined over the entity type.

It would be convenient for the translation to automatically map the "this" entity instance to the key of the entity when invoking the database implementation of the function.

@ajcvickers
Copy link
Member

@pmiddleton Let us know if you're interested in working on this.

@pmiddleton
Copy link
Contributor

Yes

@regul4rj0hn
Copy link

Please also consider an scenario like the following: I need to efficiently check some information that is encrypted by a symmetric key in the database, across several tables.

It would be nice if we could do something like _dbContext.IsEmailAvailable(email) given the mapping of scalar function in the DB to the context:

[DbFunction("IsEmailAvailable", "dbo")]
public static bool IsEmailAvailable(string Email) => throw new NotImplementedException();

You don't always need to execute the function over an specific Entity.

Thanks

@pmiddleton
Copy link
Contributor

@regul4rj0hn - Is email bound to an entity in your example? If so then you can already do that today.

If email is just a string coming in from the application then you can't. Support for use case is included in #11129 but that is on hold pending the query redesign in 3.0

@regul4rj0hn
Copy link

Yeah, it's coming from the app that's the issue. Currently calling the scalar function the old-fashioned way as a work around. I guess that refactor will have to wait then. Thanks for the help, @pmiddleton !

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

5 participants