I am using linq2couchbase 2.0.0 in a .net 5 webapi. When I call GetAll(), it returns 0 object
Startup.cs
{
Configuration.GetSection(“Application”).GetSection(“CouchBase”).Bind(options);
options.AddLinq();
}).AddCouchbaseBucket(“strike1000”);
Repository.cs
public class CouchBaseRepository : IRepository
where E : IBaseEntity
{
private string collectionName;
private string scopeName = “_default”;
private BucketContext context;
public CouchBaseRepository(INamedBucketProvider bucketProvider)
{
if (typeof(ILookup).IsAssignableFrom(typeof(E)))
{
scopeName = "lookups";
}
var attr = typeof(E).GetCustomAttributes(true).Where(w => w.GetType() == typeof(CollectionAttribute)).FirstOrDefault();
collectionName = attr != null ? ((CollectionAttribute)attr).Name : typeof(E).Name;
context = new BucketContext(bucketProvider.GetBucketAsync().Result);
}
public Task<E> Get(string id)
{
return Task.FromResult(context.Bucket.Collection(collectionName).GetAsync(id).Result.ContentAs<E>());
}
public Task<List<E>> GetAll()
{
return Task.FromResult(Query().ScanConsistency(Couchbase.Query.QueryScanConsistency.RequestPlus).ToList());
}
public async Task<E> Set(E entity)
{
if (string.IsNullOrEmpty(entity.Id))
{
entity.Id = ObjectId.GenerateNewId().ToString();
}
else
{
}
var ret=await context.Bucket.Collection(collectionName).UpsertAsync(entity.Id, entity);
//var ret = await col.UpsertAsync(entity.Id, entity);
return entity;
}
public async Task<bool> Delete(E entity)
{
await context.Bucket.Collection(collectionName).RemoveAsync(entity.Id);
return true;
}
public async Task<bool> Delete(string id)
{
await context.Bucket.Collection(collectionName).RemoveAsync(id);
return true;
}
public IQueryable<E> Query()
{
return context.Query<E>();
}
}
My record:
{
“serverId”: null,
“channelId”: null,
“status”: 0,
“keyword”: “QQQ”,
“expireDate”: null,
“winnerDate”: null,
“winner”: null,
“id”: “61dbe1e8816f264c649565ac”,
“createdBy”: null,
“updatedBy”: null,
“createdDate”: null,
“updatedDate”: null,
“type”: “KeywordRewardEntity”
}