S
S
spry2015-03-11 10:55:43
NHibernate
spry, 2015-03-11 10:55:43

How to get nHibernate, composite-id and INNER JOIN/WHERE IN together?

There is such a TSQL

SELECT Data.*
FROM [currrates_data].[dbo].[CashExchangeRates] Data
INNER JOIN (
    	SELECT
        [FinancialInstitutionCountryCode],
        [FinancialInstitutionName],
        [BaseCurrency],
        [QuoteCurrency],
        MAX([Timestamp]) AS [Timestamp]
    	FROM [currrates_data].[dbo].[CashExchangeRates]
    	GROUP BY
        [FinancialInstitutionCountryCode]
        	[FinancialInstitutionName]
        	[BaseCurrency]
          [QuoteCurrency]) Filter
ON
    	[Data].[FinancialInstitutionCountryCode] = [Filter].[FinancialInstitutionCountryCode] AND
    	[Data].[FinancialInstitutionName] = [Filter].[FinancialInstitutionName] AND
    	[Data].[BaseCurrency] = [Filter].[BaseCurrency] AND
    	[Data].[QuoteCurrency] = [Filter].[QuoteCurrency] AND
    	[Data].[Timestamp] = [Filter].[Timestamp]

How to translate this to nHibernate? It won't work through SubQuery, because CashExchangeRate has a composite-id (FinancialInstitutionCountryCode, FinancialInstitutionName, BaseCurrency, QuoteCurrency, Timestamp) which won't work through WHERE IN.
What was found: nHibernate does not support JOIN on unrelated entities, that is, JOIN on the same table cannot be done.
I see 2 options: change the structure and enter a surrogate ID (record number chtoli), or write it in raw SQL.

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question