当前位置: 首页>>代码示例>>C#>>正文


C# Mapper.Fetch方法代码示例

本文整理汇总了C#中Mapper.Fetch方法的典型用法代码示例。如果您正苦于以下问题:C# Mapper.Fetch方法的具体用法?C# Mapper.Fetch怎么用?C# Mapper.Fetch使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Mapper的用法示例。


在下文中一共展示了Mapper.Fetch方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: GetUsersByLastName

 public IEnumerable<User> GetUsersByLastName(string Lastname)
 {
     Cluster cluster = Cluster.Builder().AddContactPoint("127.0.0.1").Build();
     ISession session = cluster.Connect("demo");
     IMapper mapper = new Mapper(session);
     IEnumerable<User> users = mapper.Fetch<User>("SELECT * FROM users WHERE lastname = ?", Lastname);
     return users;
 }
开发者ID:mpatil-sapient,项目名称:mfinity_public,代码行数:8,代码来源:UserDAO.cs

示例2: CreateTable_FluentMapping_Success

        public void CreateTable_FluentMapping_Success()
        {
            var mappingConfig = new MappingConfiguration().Define(new ManyDataTypesPocoMappingCaseSensitive());
            var table = new Table<ManyDataTypesPoco>(_session, mappingConfig);
            table.Create();

            var mapper = new Mapper(_session, mappingConfig);
            ManyDataTypesPoco manyTypesInstance = ManyDataTypesPoco.GetRandomInstance();

            mapper.Insert(manyTypesInstance);
            string cqlSelect = string.Format("SELECT * from \"{0}\" where \"{1}\"='{2}'", table.Name, "StringType", manyTypesInstance.StringType);
            List<ManyDataTypesPoco> instancesQueried = mapper.Fetch<ManyDataTypesPoco>(cqlSelect).ToList();
            Assert.AreEqual(1, instancesQueried.Count);
            instancesQueried[0].AssertEquals(manyTypesInstance);
        }
开发者ID:mtf30rob,项目名称:csharp-driver,代码行数:15,代码来源:CreateTable.cs

示例3: CqlClientConfiguration_UseIndividualMappingGeneric_StaticMappingClass_

        public void CqlClientConfiguration_UseIndividualMappingGeneric_StaticMappingClass_()
        {
            var config = new MappingConfiguration().Define(new ManyDataTypesPocoMappingCaseSensitive());
            var table = new Table<ManyDataTypesPoco>(_session, config);
            Assert.AreNotEqual(table.Name, table.Name.ToLower()); // make sure the case sensitivity rule is being used
            table.Create();

            var mapper = new Mapper(_session, config);
            var manyTypesInstance = ManyDataTypesPoco.GetRandomInstance();

            mapper.Insert(manyTypesInstance);
            var instancesQueried = mapper.Fetch<ManyDataTypesPoco>().ToList();
            Assert.AreEqual(1, instancesQueried.Count);
            manyTypesInstance.AssertEquals(instancesQueried[0]);
        }
开发者ID:Virus-X,项目名称:csharp-driver,代码行数:15,代码来源:CqlClientConfig.cs

示例4: Counter_Success

        public void Counter_Success()
        {
            var config = new AttributeBasedTypeDefinition(typeof(PocoWithCounterAttribute));
            var table = new Table<PocoWithCounterAttribute>(_session, new MappingConfiguration().Define(config));
            table.Create();
            var cqlClient = new Mapper(_session, new MappingConfiguration().Define(config));

            List<PocoWithCounterAttribute> counterPocos = new List<PocoWithCounterAttribute>();
            for (int i = 0; i < 10; i++)
            {
                counterPocos.Add(
                    new PocoWithCounterAttribute()
                    {
                        KeyPart1 = Guid.NewGuid(),
                        KeyPart2 = (decimal)123,
                    });
            }

            int counterIncrements = 100;
            string updateStr = String.Format("UPDATE \"{0}\" SET \"{1}\"=\"{1}\" + 1 WHERE \"{2}\"=? and \"{3}\"=?", table.Name.ToLower(), "counter", "keypart1", "keypart2");
            var updateSession = _session.Prepare(updateStr);
            foreach (PocoWithCounterAttribute pocoWithCounter in counterPocos)
            {
                var boundStatement = updateSession.Bind(new object[] { pocoWithCounter.KeyPart1, pocoWithCounter.KeyPart2 });
                for (int j = 0; j < counterIncrements; j++)
                    _session.Execute(boundStatement);
                pocoWithCounter.Counter += counterIncrements;
            }

            List<PocoWithCounterAttribute> countersQueried = cqlClient.Fetch<PocoWithCounterAttribute>().ToList();
            foreach (PocoWithCounterAttribute pocoWithCounterExpected in counterPocos)
            {
                bool counterFound = false;
                foreach (PocoWithCounterAttribute pocoWithCounterActual in countersQueried)
                {
                    if (pocoWithCounterExpected.KeyPart1 == pocoWithCounterActual.KeyPart1)
                    {
                        Assert.AreEqual(pocoWithCounterExpected.KeyPart2, pocoWithCounterExpected.KeyPart2);
                        Assert.AreEqual(pocoWithCounterExpected.Counter, pocoWithCounterExpected.Counter);
                        counterFound = true;
                    }
                }
                Assert.IsTrue(counterFound, "Counter with first key part: " + pocoWithCounterExpected.KeyPart1 + " was not found!");
            }
        }
开发者ID:raideroflostark,项目名称:csharp-driver,代码行数:45,代码来源:Counter.cs

示例5: Insert_Sync

        public void Insert_Sync()
        {
            // Setup
            var mappingConfig = new MappingConfiguration().Define(new Map<lowercaseclassnamepklowercase>()
                .TableName(TestUtils.GetUniqueTableName().ToLowerInvariant()).PartitionKey(c => c.somepartitionkey).CaseSensitive());
            var table = new Table<lowercaseclassnamepklowercase>(_session, mappingConfig);
            Assert.AreEqual(table.Name, table.Name.ToLower());
            table.Create();

            // Insert using Mapper.Insert
            lowercaseclassnamepklowercase privateClassInstance = new lowercaseclassnamepklowercase();
            var mapper = new Mapper(_session, mappingConfig);
            mapper.Insert(privateClassInstance);
            List<lowercaseclassnamepklowercase> instancesQueried = mapper.Fetch<lowercaseclassnamepklowercase>().ToList();
            Assert.AreEqual(1, instancesQueried.Count);
            lowercaseclassnamepklowercase defaultInstance = new lowercaseclassnamepklowercase();
            Assert.AreEqual(defaultInstance.somepartitionkey, instancesQueried[0].somepartitionkey);
        }
开发者ID:jorgebay,项目名称:csharp-driver,代码行数:18,代码来源:InsertTests.cs

示例6: Fetch_UsingSelectCqlString

        public void Fetch_UsingSelectCqlString()
        {
            Table<Author> table = new Table<Author>(_session, new MappingConfiguration());
            table.Create();

            var mapper = new Mapper(_session, new MappingConfiguration().Define(new FluentUserMapping()));
            List<string> followersForAuthor = new List<string>() { "follower1", "follower2", "" };
            Author expectedAuthor = new Author
            {
                AuthorId = Guid.NewGuid().ToString(),
                Followers = followersForAuthor,
            };

            mapper.Insert(expectedAuthor);
            List<Author> authors = mapper.Fetch<Author>("SELECT * from " + table.Name).ToList();
            Assert.AreEqual(1, authors.Count);
            expectedAuthor.AssertEquals(authors[0]);
        }
开发者ID:shawhu,项目名称:csharp-driver,代码行数:18,代码来源:Fetch.cs

示例7: CreateTable_MakeAllPropertiesCaseSensitiveAtOnce

        public void CreateTable_MakeAllPropertiesCaseSensitiveAtOnce()
        {
            var config = new MappingConfiguration().Define(new Map<ManyDataTypesPoco>()
                .PartitionKey(u => u.StringType)
                .TableName("tbl_case_sens_once")
                .CaseSensitive());

            var table = new Table<ManyDataTypesPoco>(_session, config);
            table.Create();

            var mapper = new Mapper(_session, config);
            ManyDataTypesPoco manyTypesInstance = ManyDataTypesPoco.GetRandomInstance();
            mapper.Insert(manyTypesInstance);
            string cqlSelect = string.Format("SELECT * from \"{0}\" where \"{1}\"='{2}'", table.Name, "StringType", manyTypesInstance.StringType);
            List<ManyDataTypesPoco> objectsRetrieved = mapper.Fetch<ManyDataTypesPoco>(cqlSelect).ToList();
            Assert.AreEqual(1, objectsRetrieved.Count);
            objectsRetrieved[0].AssertEquals(manyTypesInstance);
        }
开发者ID:mtf30rob,项目名称:csharp-driver,代码行数:18,代码来源:CreateTable.cs

示例8: CqlClientConfiguration_UseIndividualMappingGeneric_StaticMappingClass

        public void CqlClientConfiguration_UseIndividualMappingGeneric_StaticMappingClass()
        {
            // Use separate keyspace to avoid interfering with other tests
            _uniqueKsName = TestUtils.GetUniqueKeyspaceName();
            _session.CreateKeyspace(_uniqueKsName);
            _session.ChangeKeyspace(_uniqueKsName);

            var config = new MappingConfiguration().Define(new ManyDataTypesPocoMappingCaseSensitive());
            var table = new Table<ManyDataTypesPoco>(_session, config);
            Assert.AreNotEqual(table.Name, table.Name.ToLower()); // make sure the case sensitivity rule is being used
            table.CreateIfNotExists();

            var mapper = new Mapper(_session, config);
            var manyTypesInstance = ManyDataTypesPoco.GetRandomInstance();

            mapper.Insert(manyTypesInstance);
            var instancesQueried = mapper.Fetch<ManyDataTypesPoco>().ToList();
            Assert.AreEqual(instancesQueried.Count, 1);
            manyTypesInstance.AssertEquals(instancesQueried[0]);
        }
开发者ID:mtf30rob,项目名称:csharp-driver,代码行数:20,代码来源:CqlClientConfig.cs

示例9: Main

        static void Main(string[] args)
        {
            var cluster = Cluster.Builder()
                .AddContactPoints("192.168.40.3", "192.168.40.4")
                .WithCredentials("cassandra", "cassandra")
                .Build();

            var session = cluster.Connect("inventory");

            var results = session.Execute("select * from products");
            foreach (var result in results)
            {
                Console.WriteLine(result.GetValue<string>("sku"));
            }

            var boundQuery = session.Prepare("select * from products where product_id=?");

            var boundStatement = boundQuery.Bind("p1");

            var results2 = session.Execute(boundStatement);
            foreach (var result in results2)
            {
                Console.WriteLine(result.GetValue<string>("sku"));
            }

            var mapping = new Mapper(session);

            var products = mapping.Fetch<Product>("select * from products where product_id=? and sku=?", "p1", "psku1");

            foreach (var product in products)
            {
                Console.WriteLine("SKU: {0}, Price: {1}", product.Sku, product.Price);
            }

            session.Dispose();
            cluster.Dispose();
        }
开发者ID:ashic,项目名称:cassandra-intro,代码行数:37,代码来源:Program.cs

示例10: Fetch_WithConsistencyLevel_Invalids_OnlySupportedForWrites

        public void Fetch_WithConsistencyLevel_Invalids_OnlySupportedForWrites()
        {
            Table<Author> table = new Table<Author>(_session, new MappingConfiguration());
            table.Create();
            int totalInserts = 10;

            var mapper = new Mapper(_session, new MappingConfiguration().Define(new FluentUserMapping()));
            List<Author> expectedAuthors = Author.GetRandomList(totalInserts);
            foreach (Author expectedAuthor in expectedAuthors)
                mapper.Insert(expectedAuthor);

            Cql cql = new Cql("SELECT * from " + table.Name).WithOptions(c => c.SetConsistencyLevel(ConsistencyLevel.EachQuorum));
            var err = Assert.Throws<InvalidQueryException>(() => mapper.Fetch<Author>(cql).ToList());
            Assert.AreEqual("EACH_QUORUM ConsistencyLevel is only supported for writes", err.Message);

            cql = new Cql("SELECT * from " + table.Name).WithOptions(c => c.SetConsistencyLevel(ConsistencyLevel.Any));
            err = Assert.Throws<InvalidQueryException>(() => mapper.Fetch<Author>(cql).ToList());
            Assert.AreEqual("ANY ConsistencyLevel is only supported for writes", err.Message);
        }
开发者ID:shawhu,项目名称:csharp-driver,代码行数:19,代码来源:Fetch.cs

示例11: Fetch_WithConsistencyLevel_Valids

        public void Fetch_WithConsistencyLevel_Valids()
        {
            Table<Author> table = new Table<Author>(_session, new MappingConfiguration());
            table.Create();
            int totalInserts = 10;

            var mapper = new Mapper(_session, new MappingConfiguration().Define(new FluentUserMapping()));
            List<Author> expectedAuthors = Author.GetRandomList(totalInserts);
            foreach (Author expectedAuthor in expectedAuthors)
                mapper.Insert(expectedAuthor);

            var consistencyLevels = new[]
            {
                ConsistencyLevel.All,
                ConsistencyLevel.LocalOne,
                ConsistencyLevel.LocalQuorum,
                ConsistencyLevel.Quorum,
                ConsistencyLevel.One,
            };
            foreach (var consistencyLevel in consistencyLevels)
            {
                Cql cql = new Cql("SELECT * from " + table.Name).WithOptions(c => c.SetConsistencyLevel(consistencyLevel));
                List<Author> actualAuthors = mapper.Fetch<Author>(cql).ToList();
                Assert.AreEqual(totalInserts, actualAuthors.Count);
                Author.AssertListsContainTheSame(expectedAuthors, actualAuthors);
            }
        }
开发者ID:shawhu,项目名称:csharp-driver,代码行数:27,代码来源:Fetch.cs

示例12: Fetch_UsingCqlObject

        public void Fetch_UsingCqlObject()
        {
            Table<Author> table = new Table<Author>(_session, new MappingConfiguration());
            table.Create();
            int totalInserts = 10;

            var mapper = new Mapper(_session, new MappingConfiguration().Define(new FluentUserMapping()));
            List<Author> expectedAuthors = Author.GetRandomList(totalInserts);
            foreach (Author expectedAuthor in expectedAuthors)
                mapper.Insert(expectedAuthor);

            Cql cql = new Cql("SELECT * from " + table.Name);
            List<Author> actualAuthors = mapper.Fetch<Author>(cql).ToList();
            Assert.AreEqual(totalInserts, actualAuthors.Count);
            Author.AssertListsContainTheSame(expectedAuthors, actualAuthors);
        }
开发者ID:shawhu,项目名称:csharp-driver,代码行数:16,代码来源:Fetch.cs

示例13: Insert_WithConsistency_Success

        public void Insert_WithConsistency_Success()
        {
            // Setup
            var mappingConfig = new MappingConfiguration().Define(new Map<lowercaseclassnamepklowercase>()
                .TableName(TestUtils.GetUniqueTableName().ToLowerInvariant()).PartitionKey(c => c.somepartitionkey).CaseSensitive());
            var table = new Table<lowercaseclassnamepklowercase>(_session, mappingConfig);
            table.Create();
            var mapper = new Mapper(_session, mappingConfig);

            // Insert the data
            var consistencyLevels = new []
            {
                ConsistencyLevel.All,
                ConsistencyLevel.Any,
                ConsistencyLevel.EachQuorum,
                ConsistencyLevel.LocalOne,
                ConsistencyLevel.LocalQuorum,
                ConsistencyLevel.Quorum,
            };
            foreach (var consistencyLevel in consistencyLevels)
            {
                lowercaseclassnamepklowercase pocoInstance = new lowercaseclassnamepklowercase();
                pocoInstance.somepartitionkey = Guid.NewGuid().ToString();
                mapper.Insert(pocoInstance, new CqlQueryOptions().SetConsistencyLevel(consistencyLevel));

                // Assert final state of C* data
                string cql = "Select * from " + table.Name + " where somepartitionkey ='" + pocoInstance.somepartitionkey + "'";
                List<lowercaseclassnamepklowercase> instancesQueried = mapper.Fetch<lowercaseclassnamepklowercase>(cql).ToList();
                DateTime futureDateTime = DateTime.Now.AddSeconds(2);
                while (instancesQueried.Count < 1 && futureDateTime > DateTime.Now)
                {
                    instancesQueried = mapper.Fetch<lowercaseclassnamepklowercase>(cql).ToList();
                }
                Assert.AreEqual(1, instancesQueried.Count, "Unexpected failure for consistency level: " + consistencyLevel);
                Assert.AreEqual(pocoInstance.somepartitionkey, instancesQueried[0].somepartitionkey);
            }
        }
开发者ID:jorgebay,项目名称:csharp-driver,代码行数:37,代码来源:InsertTests.cs

示例14: Fetch_Lazy

        public void Fetch_Lazy()
        {
            Table<Author> table = new Table<Author>(_session, new MappingConfiguration());
            table.Create();

            var mapper = new Mapper(_session, new MappingConfiguration().Define(new FluentUserMapping()));
            List<Author> expectedAuthors = Author.GetRandomList(100);
            foreach (Author expectedAuthor in expectedAuthors)
                mapper.Insert(expectedAuthor);

            // wait until all records are available to be fetched: 
            List<Author> authors = mapper.Fetch<Author>("SELECT * from " + table.Name).ToList();
            DateTime futureDateTime = DateTime.Now.AddSeconds(10);
            while (authors.Count < expectedAuthors.Count && DateTime.Now < futureDateTime)
                authors = mapper.Fetch<Author>("SELECT * from " + table.Name).ToList();
            Assert.AreEqual(expectedAuthors.Count, authors.Count, "Setup FAIL: Less than expected number of authors uploaded");

            Cql cql = new Cql("SELECT * from " + table.Name).WithOptions(o => o.SetConsistencyLevel(ConsistencyLevel.Quorum));
            List<Author> authorsFetchedAndSaved = new List<Author>();
            var authorsFetched = mapper.Fetch<Author>(cql).GetEnumerator();
            while (authorsFetched.MoveNext())
                authorsFetchedAndSaved.Add(authorsFetched.Current);

            Assert.AreEqual(expectedAuthors.Count, authorsFetchedAndSaved.Count);
            foreach (var authorFetched in authorsFetchedAndSaved)
            {
                Author.AssertListContains(expectedAuthors, authorFetched);
            }
        }
开发者ID:shawhu,项目名称:csharp-driver,代码行数:29,代码来源:Fetch.cs

示例15: Insert_TableNameLowerCase_PartitionKeyLowerCase

        public void Insert_TableNameLowerCase_PartitionKeyLowerCase()
        {
            var tableName = TestUtils.GetUniqueTableName().ToLowerInvariant();
            var mappingConfig = new MappingConfiguration().Define(new Map<lowercaseclassnamepklowercase>().TableName(tableName).PartitionKey(c => c.somepartitionkey));
            Table<lowercaseclassnamepklowercase> table = new Table<lowercaseclassnamepklowercase>(_session, mappingConfig);
            table.Create();

            var cqlClient = new Mapper(_session, new MappingConfiguration());
            lowercaseclassnamepklowercase defaultPocoInstance = new lowercaseclassnamepklowercase();

            cqlClient.Insert(defaultPocoInstance);
            List<lowercaseclassnamepklowercase> instancesQueried = cqlClient.Fetch<lowercaseclassnamepklowercase>().ToList();
            Assert.AreEqual(1, instancesQueried.Count);
            lowercaseclassnamepklowercase defaultInstance = new lowercaseclassnamepklowercase();
            Assert.AreEqual(defaultInstance.somepartitionkey, instancesQueried[0].somepartitionkey);

            // using standard cql
            string cqlLowerCasePartitionKey = "SELECT * from " + typeof(lowercaseclassnamepklowercase).Name + " where \"somepartitionkey\" = '" + defaultPocoInstance.somepartitionkey + "'";
            List<Row> rows = _session.Execute(cqlLowerCasePartitionKey).GetRows().ToList();
            Assert.AreEqual(1, rows.Count);
            Assert.AreEqual(defaultPocoInstance.somepartitionkey, rows[0].GetValue<string>("somepartitionkey"));

        }
开发者ID:Virus-X,项目名称:csharp-driver,代码行数:23,代码来源:InsertTests.cs


注:本文中的Mapper.Fetch方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。