This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class IgnoreFieldContractResolver : DefaultContractResolver | |
{ | |
public IgnoreFieldContractResolver() { } | |
public IgnoreFieldContractResolver(string fieldToIgnore) | |
{ | |
FieldToIgnore = fieldToIgnore; | |
} | |
public string FieldToIgnore { get; set; } | |
protected override IList<JsonProperty> CreateProperties(Type type, MemberSerialization memberSerialization) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using (var cluster = new Cluster(new ClientConfiguration | |
{ | |
SerializationSettings = | |
new JsonSerializerSettings | |
{ | |
ContractResolver = new IgnoreFieldContractResolver("_id") | |
} | |
})) | |
{ | |
using (var bucket = cluster.OpenBucket()) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"_id":"25892e17-80f6-415f-9c65-7395632f0223", | |
"QueueName":"Session", | |
"CreateTime":"1409954067", | |
"ModTime":"1409954067" | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public static IDocumentResult<T> ExtractKeyAndInsert<T>(this IBucket bucket, string json, string fieldNameForId, out string id) | |
{ | |
var type = typeof (T); | |
var document = type == typeof (object) ? | |
GetDocumentForDynamic<T>(json, fieldNameForId, out id) : | |
GetDocumentForPOCO<T>(type, json, fieldNameForId, out id); | |
return bucket.Insert(document); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//read from disk | |
var json = File.ReadAllText("Data\\doc-with-embedded-id.json"); | |
//insert for a POCO | |
bucket.ExtractKeyAndInsert<QueueItem>(json, "Id"); | |
//insert for a dynamic or object type | |
var insert = _bucket.ExtractKeyAndInsert<dynamic>(json, "_id"); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using (var bucket = Cluster.OpenBucket("default")) | |
{ | |
var removeTasks = items.Select(item => bucket.GetAsync<int>(item.Key)).ToList(); | |
var insertTasks = items.Select(item => bucket.GetAsync<int>(item.Key)).ToList(); | |
var getTasks = items.Select(item => bucket.GetAsync<int>(item.Key)).ToList(); | |
var removeResults = await Task.WhenAll(removeTasks).ConfigureAwait(false); | |
var insertResults = await Task.WhenAll(insertTasks).ConfigureAwait(false); | |
var getResults = await Task.WhenAll(getTasks).ConfigureAwait(false); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using Couchbase.N1QL; | |
namespace Couchbase.NetClient.N1QLExample | |
{ | |
class Program | |
{ | |
static void Main(string[] args) | |
{ | |
using (var cluster = new Cluster()) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public async void UpsertAndGet() | |
{ | |
using (var cluster = new Cluster()) | |
{ | |
using (var bucket = cluster.OpenBucket()) | |
{ | |
var upsert = await bucket.UpsertAsync("mykey", new | |
{ | |
Foo = "foo", | |
Bar = 10 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var config = new ClientConfiguration | |
{ | |
EnableTcpKeepAlives = true, //default it true | |
TcpKeepAliveTime = 1000*60*60, //set to 60mins | |
TcpKeepAliveInterval = 5000 //KEEP ALIVE will be sent every 5 seconds after 1hr | |
}; | |
var cluster = new Cluster(config); | |
var bucket = cluster.OpenBucket(); | |
//use the bucket... |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using (var bucket = _cluster.OpenBucket()) | |
{ | |
var queryRequest = new QueryRequest() | |
.Statement("SELECT * FROM `beer-sample` LIMIT $1") | |
.AddPositionalParameter(10); | |
var result = await bucket.QueryAsync<dynamic>(queryRequest); | |
Assert.IsTrue(result.Success); | |
Assert.AreEqual(10, result.Rows.Count); | |
} |
OlderNewer