Skip to content

SecondLevelCache CreateSQLQuery().UniqueResult<int>() throws Exception Specified cast is not valid. #1385

Closed
@joesun99

Description

@joesun99

Hi

Please check if this is a bug i get Exception: System.InvalidCastException : Specified cast is not valid.

For test case these two flags must be enabled:

 cache.use_second_level_cache=true 
 cache.use_query_cache=true 

TestCase:

[Test]
public void QueryCacheWithScalarFunctionThatReturnsInt()
{
	using (ISession s = OpenSession())
	{
		int result =  s
			.CreateSQLQuery("SELECT [dbo].[TestQueryCache] ()")
			.SetCacheable(true)
			.UniqueResult<int>();

		Assert.IsNotNull(result);
	}
}

Mssql scalar function create:

USE [nhibernate]
GO

/****** Object:  UserDefinedFunction [dbo].[TestQueryCache]    Script Date: 17.10.2017 14:11:13 ******/
SET ANSI_NULLS ON
GO

SET QUOTED_IDENTIFIER ON
GO

-- =============================================
-- Author:		<Author,,Name>
-- Create date: <Create Date, ,>
-- Description:	<Description, ,>
-- =============================================
CREATE FUNCTION [dbo].[TestQueryCache] 
()
RETURNS INT
AS
BEGIN
	
	RETURN DATEPART(YEAR, GETUTCDATE()) * 100 + DATEPART(MONTH, GETUTCDATE());

END

GO

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions