本文整理汇总了C#中Mapper.InsertIfNotExists方法的典型用法代码示例。如果您正苦于以下问题:C# Mapper.InsertIfNotExists方法的具体用法?C# Mapper.InsertIfNotExists怎么用?C# Mapper.InsertIfNotExists使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Mapper
的用法示例。
在下文中一共展示了Mapper.InsertIfNotExists方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: InsertIfNotExists_Applied_Test
public void InsertIfNotExists_Applied_Test()
{
var config = new MappingConfiguration()
.Define(new Map<Song>().PartitionKey(s => s.Id).TableName("song_insert"));
//Use linq to create the table
new Table<Song>(_session, config).Create();
var mapper = new Mapper(_session, config);
var song = new Song {Id = Guid.NewGuid(), Artist = "Led Zeppelin", Title = "Good Times Bad Times"};
//It is the first song there, it should apply it
var appliedInfo = mapper.InsertIfNotExists(song);
Assert.True(appliedInfo.Applied);
Assert.Null(appliedInfo.Existing);
//Following times, it should not apply the mutation as the partition key is the same
var nextSong = new Song { Id = song.Id, Title = "Communication Breakdown" };
appliedInfo = mapper.InsertIfNotExists(nextSong);
Assert.False(appliedInfo.Applied);
Assert.NotNull(appliedInfo.Existing);
Assert.AreEqual(song.Title, appliedInfo.Existing.Title);
}