1
votes

I have 2 EntityFramework contexts and corresponding API controllers.
I have 2 Breeze entityManager.
I read some Country data with entityManager1.
I read some Company data with entityManager2.

Now I wand to display the following list:
CompanyName1 CountryName1
CompanyName2 CountryName2
etc.

In Knockout it would look something like this:

<table data-bind="foreach: companies">
  <tr>
    <td data-bind="text: name"></td>
    <td data-bind="text: country().name"></td>   <!-- from another entitymanager -->
  </tr>
</table>

Is this possible. I have tried:
- using exportEntities on entityManager1 / importEntities on entityManager2
- added a second dataService to entityManager2, so the same metadata of entityManager1 is available

No luck so fare.
Is there a way to solve this?
Is there a way to combine the data from one entityManager with onther one?
Is there a way to setup an foreign key relationship between two different metadataStores entites?

Thankx, Cheers Harry

2

2 Answers

1
votes

I'm betting that you expected to be able to navigate from an entity defined in one model to an entity defined in a different model. Is that correct?

If so, that won't work ... not "out of the box". The Breeze EntityManager allows entities from different models to co-habitate in the cache. But it can't make up a navigation between entities of different models.

For example, suppose Company is defined in DbContext #1 and Country in DbContext #2 AND you have arranged for two different metadata sources, one from DBC#1 (e.g., new EFContextProvider<DBC1>().Metadata) and one from DBC#2 (e.g, new EFContextProvider<DBC2>().Metadata).

You won't be able to write aCompany.Country() and get a Country instance from Model #2. Not in Entity Framework on the server. Not on a Breeze client (without some cleverness). The reason is simple: Company and Country are defined in different model schemas. They might is well be in different databases hosted on different servers in completely different technologies.

Now you could make up your own client-side Company property to do the navigation to Country for you. Is that what you want to do?

FWIW, you can't navigate from an entity in one manager to an entity in a different manager even if entities are defined in the same model schema. EntityManagers are strictly isolated from each other. If Company and Country are defined in the same schema and for some reason you have a Company in one manager and the related Country in a different manager, then you'll have to import one or the other (e.g., the Country into the Company's manager) if you want to navigate between the instances. I'm saying this for clarity. I assume this is not the issue because you said you tried importing entities and it didn't work.

Let's step back. What are you trying to do? Why are these entities defined in different DbContexts?

0
votes

Exporting entities from one EntityManager and importing them into another should have worked. What was the issue?