@@ -650,5 +650,74 @@ public void TestScalarValuedStoredFunctions_with_null_StoreFunctionName()
650650 Assert . That ( echo , Is . EqualTo ( 1337 ) ) ;
651651 }
652652 }
653+
654+ [ Test ]
655+ public void TestCastFunction ( )
656+ {
657+ using ( var context = new BloggingContext ( ConnectionString ) )
658+ {
659+ context . Database . Log = Console . Out . WriteLine ;
660+
661+ var varbitVal = "10011" ;
662+
663+ var blog = new Blog
664+ {
665+ Name = "_" ,
666+ Posts = new List < Post >
667+ {
668+ new Post
669+ {
670+ Content = "Some post content" ,
671+ Rating = 1 ,
672+ Title = "Some post Title" ,
673+ VarbitColumn = varbitVal
674+ }
675+ }
676+ } ;
677+ context . Blogs . Add ( blog ) ;
678+ context . SaveChanges ( ) ;
679+
680+ Assert . IsTrue (
681+ context . Posts . Select (
682+ p => NpgsqlTypeFunctions . Cast ( p . VarbitColumn , "varbit" ) == varbitVal ) . First ( ) ) ;
683+
684+ Assert . IsTrue (
685+ context . Posts . Select (
686+ p => NpgsqlTypeFunctions . Cast ( p . VarbitColumn , "varbit" ) == "10011" ) . First ( ) ) ;
687+ }
688+ }
689+
690+ [ Test ]
691+ public void Test_issue_27_select_ef_generated_literals_from_inner_select ( )
692+ {
693+ using ( var context = new BloggingContext ( ConnectionString ) )
694+ {
695+ context . Database . Log = Console . Out . WriteLine ;
696+
697+ var blog = new Blog { Name = "Hello" } ;
698+ context . Users . Add ( new Administrator { Blogs = new List < Blog > { blog } } ) ;
699+ context . Users . Add ( new Editor ( ) ) ;
700+ context . SaveChanges ( ) ;
701+
702+ var administrator = context . Users
703+ . Where ( x => x is Administrator ) // Removing this changes the query to using a UNION which doesn't fail.
704+ . Select (
705+ x => new
706+ {
707+ // causes entity framework to emit a literal discriminator
708+ Computed = x is Administrator
709+ ? "I administrate"
710+ : x is Editor
711+ ? "I edit"
712+ : "Unknown" ,
713+ // causes an inner select to be emitted thus showing the issue
714+ HasBlog = x . Blogs . Any ( )
715+ } )
716+ . First ( ) ;
717+
718+ Assert . That ( administrator . Computed , Is . EqualTo ( "I administrate" ) ) ;
719+ Assert . That ( administrator . HasBlog , Is . True ) ;
720+ }
721+ }
653722 }
654723}
0 commit comments