-
Notifications
You must be signed in to change notification settings - Fork 3.2k
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
query type with fluent api #13286
Comments
@herme063 Query types are for mapping types that do not have any property or combination of properties that can act as a unique primary key. This is incompatible with many-to-many relationships since it requires both types on the end of the relationship must have a key. What is your intention in using query types for this? |
Owners table is in a different database but I want to be able to fetch it with ObjectA without needing a separate step. |
@herme063 It's not clear to me how query types helps with that scenario. Can you give some more details? |
The users of my application can create objects that they own. The user data table is in a different database than the objects table. When I fetch the objects using ef core, I need to pull the related owner/user data(currently just Id and Name). So, I am planning to create a view; then configure an Owner class to point to that view. I would like for Owner to be read only and it should not be part of code first migration. May be we can't use query type for this, if so how would we configure the above scenario using fluent api? |
@ajcvickers "If the rows returned from the view have keys, then just map them using entity types in the normal way." I pretty much have the same case as the OP (except I use a synonym of a table from a different DB, not a view) and can't figure out how to point to it in a navigation property. |
@Heresiarch88 If you have a view where each row has a unique value that can act as a primary key, the map it as a view, and create a relationship to it in the normal way--that is, the related entity will have a property acting as an FK that correlates with the key values from the view. |
I am trying to write a fluent configuration for a one to many query type.
I configured the owner as follow
modelBuilder.Query<Owner>().ToView("View_SystemUsers");
, and ObjectA has something like thisThis will give me the following error:
System.InvalidOperationException: Unable to create a foreign key with the query type 'Owner' as the principal type. Only entity types are allowed as foreign key principal types.
I am unable to find an one-to-many example for query types, most example online are one-to-one. My case is one to many as one Owner can have multiple ObjectA.
The text was updated successfully, but these errors were encountered: