Permalink
Browse files

Using collection table for GetById and Delete

  • Loading branch information...
sebastienros committed Jun 11, 2018
1 parent 1537072 commit 8c30e7c655e29daf66f7353cdc54d5876ce11faf
Showing with 42 additions and 2 deletions.
  1. +5 −2 src/YesSql.Core/Session.cs
  2. +37 −0 test/YesSql.Tests/CoreTests.cs
@@ -189,7 +189,9 @@ private async Task<Document> GetDocumentByIdAsync(int id)
{
Demand();
var command = "select * from " + _dialect.QuoteForTableName(_store.Configuration.TablePrefix + "Document") + " where " + _dialect.QuoteForColumnName("Id") + " = @Id";
var documentTable = CollectionHelper.Current.GetPrefixedName(YesSql.Store.DocumentTable);
var command = "select * from " + _dialect.QuoteForTableName(_store.Configuration.TablePrefix + documentTable) + " where " + _dialect.QuoteForColumnName("Id") + " = @Id";
var key = new WorkerQueryKey(nameof(GetDocumentByIdAsync), new [] { id });
var result = await _store.ProduceAsync(key, () => _connection.QueryAsync<Document>(command, new { Id = id }, _transaction));
@@ -256,7 +258,8 @@ private async Task DeleteEntityAsync(object obj)
Demand();
var command = "select * from " + _dialect.QuoteForTableName(_store.Configuration.TablePrefix + "Document") + " where " + _dialect.QuoteForColumnName("Id") + " " + _dialect.InOperator("@Ids");
var documentTable = CollectionHelper.Current.GetPrefixedName(YesSql.Store.DocumentTable);
var command = "select * from " + _dialect.QuoteForTableName(_store.Configuration.TablePrefix + documentTable) + " where " + _dialect.QuoteForColumnName("Id") + " " + _dialect.InOperator("@Ids");
var key = new WorkerQueryKey(nameof(GetAsync), ids);
var documents = await _store.ProduceAsync(key, () =>
@@ -2520,6 +2520,43 @@ public async Task ShouldFilterMapIndexPerCollection()
}
}
[Fact]
public async Task ShouldGetAndDeletePerCollection()
{
await _store.InitializeCollectionAsync("Collection1");
using (new NamedCollection("Collection1"))
{
using (var session = _store.CreateSession())
{
var bill = new Person
{
Firstname = "Bill",
Lastname = "Gates",
};
session.Save(bill);
}
using (var session = _store.CreateSession())
{
var person = await session.Query<Person>().FirstOrDefaultAsync();
Assert.NotNull(person);
person = await session.GetAsync<Person>(person.Id);
Assert.NotNull(person);
session.Delete(person);
}
using (var session = _store.CreateSession())
{
var person = await session.Query<Person>().FirstOrDefaultAsync();
Assert.Null(person);
}
}
}
[Fact]
public virtual async Task ShouldIndexWithDateTime()
{

0 comments on commit 8c30e7c

Please sign in to comment.