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

Add key values sugar #7391

Open
ajcvickers opened this issue Jan 11, 2017 · 7 comments
Open

Add key values sugar #7391

ajcvickers opened this issue Jan 11, 2017 · 7 comments

Comments

@ajcvickers
Copy link
Member

ajcvickers commented Jan 11, 2017

It seems common to need to do things with key values--see #7308 for some examples.

Some things to consider:

@bricelam
Copy link
Contributor

@NickStrupat likes retrieving primary key values too... 👀

@NickStrupat
Copy link

NickStrupat commented Jan 13, 2017

Hi @bricelam, @ajcvickers,

The first two points are supported by my project EntityFramework.PrimaryKey, but the FK values is something I didn't think of. It sounds interesting and useful.

How do you imagine the query clause building would look and/or work?

@ajcvickers
Copy link
Member Author

ajcvickers commented Jan 13, 2017

@sjb-sjb
Copy link

sjb-sjb commented Jun 28, 2017

@ajcvickers can you provide a workaround showing how to call TryGetEntry ?
I am on 1.1.1 and having a hard time wending my way through the GitHub code to implement a function dbSet.TryFind( object[] primaryKeyValues) per your bullet #2 above.

Just like in EntityFinder.FindTracked, I want to return _stateManager.TryGetEntry(key, keyValues)?.Entity as TEntity, but I don't see how to get to there from the public interface.

It could be either dbSet.TryFind or context.TryFind.

sjb

@ajcvickers
Copy link
Member Author

@sjb-sjb If you're asking about public API for this, then there isn't any. The only option using the public API would be to use DbSet.Local, possibly also keeping your own map if needed for perf.

If you're willing to risk using internal APIs and are okay with reacting and updating when they break, then, try something like:

var stateManager = context.GetService<IStateManager>();
var key = context.Model.FindEntityType(typeof(TEntity)).FindPrimaryKey();
var entity = stateManager.TryGetEntry(key, new object[] { myKeyValue })?.Entity;

@sjb-sjb
Copy link

sjb-sjb commented Jun 30, 2017

Thanks!

@ajcvickers
Copy link
Member Author

Consider also creating a state manager index when a unique index (as opposed to an alternate key) is defined in the node. See #28263.

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

6 participants