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


C# Mapper.Insert方法代码示例

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


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

示例1: CqlClient_Timestamp

        public void CqlClient_Timestamp()
        {
            var config = new MappingConfiguration()
                .Define(new Map<Song>().PartitionKey(s => s.Id).TableName("song_insert"));

            //Use linq to create the table
            var table = new Table<Song>(_session, config);
            table.CreateIfNotExists();
            var mapper = new Mapper(_session, config);
            var song = new Song
            {
                Id = Guid.NewGuid(),
                Artist = "The Who",
                Title = "Substitute",
                ReleaseDate = DateTimeOffset.UtcNow
            };
            //Set timestamp to 1 day ago
            var timestamp = DateTimeOffset.Now.Subtract(TimeSpan.FromDays(1));
            mapper.Insert(song, true, CqlQueryOptions.New().SetTimestamp(timestamp));

            //query for timestamp in a column of the record
            var cqlLowerCasePartitionKey = "SELECT WRITETIME (Artist) AS timestamp FROM " + table.Name + " WHERE Id = " + song.Id + ";";
            var rows = _session.Execute(cqlLowerCasePartitionKey).GetRows().ToList();
            Assert.AreEqual(1, rows.Count);

            var creationTimestamp = rows[0].GetValue<long>("timestamp");
            Assert.NotNull(creationTimestamp);
            //Timestamp retrieved is in macroseconds. Converting it to milliseconds
            Assert.AreEqual(TypeSerializer.SinceUnixEpoch(timestamp).Ticks / 10, rows[0].GetValue<object>("timestamp"));
        }
开发者ID:yar1k0v,项目名称:csharp-driver,代码行数:30,代码来源:InsertTests.cs

示例2: FetchAsync_Using_Select_Cql_And_PageSize

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

            var mapper = new Mapper(_session, new MappingConfiguration().Define(new FluentUserMapping()));
            var ids = new[] {Guid.NewGuid().ToString(), Guid.NewGuid().ToString()};

            mapper.Insert(new Author { AuthorId = ids[0] });
            mapper.Insert(new Author { AuthorId = ids[1] });

            List<Author> authors = null;
            mapper.FetchAsync<Author>(Cql.New("SELECT * from " + table.Name).WithOptions(o => o.SetPageSize(int.MaxValue))).ContinueWith(t =>
            {
                authors = t.Result.ToList();
            }).Wait();
            Assert.AreEqual(2, authors.Count);;
            CollectionAssert.AreEquivalent(ids, authors.Select(a => a.AuthorId));
        }
开发者ID:GoldenCrystal,项目名称:csharp-driver,代码行数:19,代码来源:Fetch.cs

示例3: CqlClientConfiguration_UseIndividualMappingClassType_StaticMappingClass

        public void CqlClientConfiguration_UseIndividualMappingClassType_StaticMappingClass()
        {
            var config = new MappingConfiguration().Define(new ManyDataTypesPocoMappingCaseSensitive());
            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);
            ManyDataTypesPoco.KeepTryingSelectAndAssert(mapper, cqlSelect, new List<ManyDataTypesPoco>() { manyTypesInstance });
        }
开发者ID:Virus-X,项目名称:csharp-driver,代码行数:13,代码来源:CqlClientConfig.cs

示例4: 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

示例5: 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

示例6: CreateTable_MakeAllPropertiesCaseSensitiveAtOnce

        public void CreateTable_MakeAllPropertiesCaseSensitiveAtOnce()
        {
            var config = new MappingConfiguration().Define(new Map<ManyDataTypesPoco>()
                .PartitionKey(u => u.StringType)
                .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:Virus-X,项目名称:csharp-driver,代码行数:17,代码来源:CreateTable.cs

示例7: CqlClientConfiguration_UseIndividualMappingClassType_StaticMappingClass

        public void CqlClientConfiguration_UseIndividualMappingClassType_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);
            table.CreateIfNotExists();

            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);
            ManyDataTypesPoco.KeepTryingSelectAndAssert(mapper, cqlSelect, new List<ManyDataTypesPoco>() { manyTypesInstance });
        }
开发者ID:mtf30rob,项目名称:csharp-driver,代码行数:18,代码来源:CqlClientConfig.cs

示例8: 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

示例9: 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

示例10: 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

示例11: Fetch_ListUploadedAsNull

        public void Fetch_ListUploadedAsNull()
        {
            Table<Author> table = new Table<Author>(_session, new MappingConfiguration());
            table.Create();
            var mapper = new Mapper(_session, new MappingConfiguration().Define(new FluentUserMapping()));
            Author expectedAuthor = Author.GetRandom();
            expectedAuthor.Followers = null;
            mapper.Insert(expectedAuthor);

            // Assert values from cql query
            Author expectedAuthorFromQuery = new Author
            {
                Followers = new List<string>(), // not null
                AuthorId = expectedAuthor.AuthorId,
            };

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

示例12: 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

示例13: Fetch_WithConsistencyLevel_Invalids_NotEnoughReplicas

        public void Fetch_WithConsistencyLevel_Invalids_NotEnoughReplicas()
        {
            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.Two));
            var err = Assert.Throws<UnavailableException>(() => mapper.Fetch<Author>(cql));
            Assert.AreEqual("Not enough replicas available for query at consistency Two (2 required but only 1 alive)", err.Message);

            cql = new Cql("SELECT * from " + table.Name).WithOptions(c => c.SetConsistencyLevel(ConsistencyLevel.Three));
            err = Assert.Throws<UnavailableException>(() => mapper.Fetch<Author>(cql));
            Assert.AreEqual("Not enough replicas available for query at consistency Three (3 required but only 1 alive)", err.Message);
        }
开发者ID:shawhu,项目名称:csharp-driver,代码行数:19,代码来源:Fetch.cs

示例14: 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

示例15: 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


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