Beispiel #1
0
        public void ConversionToTsVector()
        {
            using (var context = new BloggingContext(ConnectionString))
            {
                context.Database.Log = Console.Out.WriteLine;

                context.Blogs.Add(new Blog {
                    Name = "_"
                });
                context.SaveChanges();

                const string expected = "'a':5 'b':10";
                var          casted   = context.Blogs.Select(x => NpgsqlTextFunctions.AsTsVector(expected)).First();
                Assert.That(
                    NpgsqlTsVector.Parse(casted).ToString(),
                    Is.EqualTo(NpgsqlTsVector.Parse(expected).ToString()));

                var converted = context.Blogs.Select(x => NpgsqlTextFunctions.ToTsVector("banana car")).First();
                Assert.That(
                    NpgsqlTsVector.Parse(converted).ToString(),
                    Is.EqualTo(NpgsqlTsVector.Parse("'banana':1 'car':2").ToString()));

                converted = context.Blogs.Select(x => NpgsqlTextFunctions.ToTsVector("english", "banana car")).First();
                Assert.That(
                    NpgsqlTsVector.Parse(converted).ToString(),
                    Is.EqualTo(NpgsqlTsVector.Parse("'banana':1 'car':2").ToString()));
            }
        }
Beispiel #2
0
        public void TsVectorConcat()
        {
            using (var context = new BloggingContext(ConnectionString))
            {
                context.Database.Log = Console.Out.WriteLine;

                context.Blogs.Add(new Blog {
                    Name = "_"
                });
                context.SaveChanges();

                var result = context.Blogs.Select(
                    x => NpgsqlTextFunctions.AsTsVector("a:1 b:2")
                    + NpgsqlTextFunctions.AsTsVector("c:1 d:2 b:3")).First();

                Assert.That(
                    NpgsqlTsVector.Parse(result).ToString(),
                    Is.EqualTo(NpgsqlTsVector.Parse("'a':1 'b':2,5 'c':3 'd':4").ToString()));
            }
        }