سؤال

I'm trying to join two tables from two different catalogs but I'm not able to get to work.

I know I have to do something with CatalogNameOVerwriteHashtable but apparently I'm doing something wrong.

The documentation link (http://www.llblgen.com/documentation/2.6/using%20the%20generated%20code/Adapter/gencode_dataaccessadapter_adapter.htm) doesn't give enough information to resolve my challenge.

I have the following situation:

  • I've got two Catalogs: CatalogA and CatalogB
  • There's Article-table in CatalogA and a StockCount-table in CatalogB

I've created a manual relation. So far so good.

My guess is that I have the following actions:

  • Create a new CatalogNameOverwriteHashtable instance: var foo = new CatalogNameOverwriteHashtable();
  • foo.Add("StockCount", "CatalogA");
  • foo.Add("Article", "CatalogB");
  • Assign it to the adapter: adapter.CatalogNameOverwrites = foo;

Which results in the following query:

SELECT 
[dbo].[StockCount].[ArticleId], 
[dbo].[Article].[Description], 
[dbo].[StockCount].[ShopId], 
[dbo].[StockCount].[LastMutationDateTime]
FROM ( [dbo].[StockCount] INNER JOIN 
[dbo].[Article] ON [dbo].[StockCount].[ArticleId]=[dbo].[Article].[ArticleId])

Clearly I'm doing something wrong because the catalog name is missing in the query. The question is, what?

هل كانت مفيدة؟

المحلول

In the end the solution is very simple and proves why LLBLGen is so powerful and easy to use.

First of all. When you generate your entities the catalog name is stored in FieldInfoProviders. This can be retrieved with following instruction:

var catalogName = ORMapper.Utils.DatabasePersistenceInfo.GetFieldPersistenceInfo(ArticleFields.PKey).SourceCatalogName;

This catalog name is the catalog you used to generate the entities against. This is probably your development database.

Next thing you do is map the development catalog name with the production catalog name. Like so:

adapter = new DataAccessAdapter("Your connection string");
adapter.CatalogNameOverwrites =new CatalogNameOverwriteHashtable();
adapter.CatalogNameOverwrites.Add(catalogName, "ProductionCatalogName");
مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top