How to async join tables in RavenDB - asynchronous

I need to do query from two raven db tables.
I found almoust perfect solution in documentation, only problem is im using async session and have no idea what is async equivalent.
var q = from order in dq
let company = session.Load<Company>(order.Company)
select new
{
order.Freight,
company.Name
};

The correct syntax is:
RavenQuery.Load<Company>(order.Company)
https://ravendb.net/docs/article-page/5.4/csharp/indexes/querying/projections#example-viii---projection-using-a-loaded-document

Related

How to select & update a single field using EF Core 3.1

How to implement this feature like:
UPDATE BlogSite
SET PostCount = PostCount + 1
WHERE BlogId = #BlogId
base on entity framework 3.1 (MySQL)
// I assume your DBContext object is _db.
var blogSite=_db.BlogSite.Find(BlogId);
blogSite.PostCount++;
_db.SaveChanges();
Addition to #sadullah's answer,
In order to make it atomic and performant, I suggest you to wrap it by a transaction since you are having two db operations (select, update). And also you might want to consider using async versions of efcore's functions.
using (var transaction = await _yourDbContext.Database.BeginTransactionAsync())
{
var entry = await _yourDbContext.BlogSite.FindAsync(*);
entry.PostCount++;
await _yourDbContext.SaveChangesAsync();
await transaction.CommitAsync();
}

Entity Framework query to return list with simple filter

Is there a simple way to modify this code to return only records where LocationID matches the id I'm trying to pass as a parameter? Needless to say, this doesn't compile. I thought Entity Framework was meant to make things easier, but I've searched online and can't find an understandable example of how to assign a simple query where a field in a single table/entity matches a number.
public async Task<List<PC>> GetPCsAsync(int id)
{
// Get our data. Don't yet know how to feed the variable to EF/Linq
PCList = await (from p in db.PC
select new PC {p.LocationID = id}).ToListAsync();
return PCList;
}
Thanks.
And also if you want to do it using Query Syntax it would be something like this:
PCList = await (from p in db.PC
where p.LocationID == id
select p).ToListAsync();
Here's a link to understand the differences between Query and Method syntax.
var list = db.PC.Where(x=>x.LocationID == id).ToList();
for async
var listAsync = await db.PC.Where(x=>x.LocationID == id).ToListAsync();
I hope it's help you!

Azure Mobile Service Sync with select clause not supported?

I’ve had a sync operation in place in my Xamarin Forms app for a long time now and only this pase couple of weeks has it started throwing exceptions, which makes me think maybe it’s a service change or something introduced in an update?
On startup I sync all data with m Azure Mobile Service using:
await this.client.SyncContext.PushAsync();
if (signedInUser != Guid.Empty)
{
await this.MyTable.PullAsync(
"myWorkoutsOnly",
this.MyTable.CreateQuery().Select(u => u.UserId == signedInUser));
}
And as I say, I’ve never had an issue with this code. Now though, I’m getting:
System.ArgumentException: Pull query with select clause is not supported
I only want to sync the data that matches the signed in user, so is there another way to achieve this?
I only want to sync the data that matches the signed in user, so is there another way to achieve this?
You could leverage the code below to achieve your purpose as follows:
var queryName = $"incsync_{UserId}";
var query = table.CreateQuery()
.Where(u => u.UserId == signedInUser);
await table.PullAsync(queryName, query);
For Select method, you could retrieve the specific properties into your local store instead of all properties in your online table as follows:
var queryName = $"incsync:s:{typeof(T).Name}";
var query = table.CreateQuery()
.Select(r => new { r.Text, r.Complete, r.UpdatedAt, r.Version });
await table.PullAsync(queryName, query);
For more details, you could refer to adrian hall's book about Query Management.
UPDATE:
As Joagwa commented, you could change your server side code and limit data to be retrieved only by the logged in user. For more details, you could refer to Data Projection and Queries > Per-User Data.

firebase equivalent to sql where in ()

I need a firebase query that is equivalent to this query in SQL:
select * from your_table where id in (123, 345, 679)
How would you do this logic in firebase?
thx,
Firebase's queries don't have an OR or IN operator. So you cannot easily map the above query to Firebase.
One workaround would be to implement a function that simply loops over the elements:
function loadThese(ids, callback) {
var rows = [];
while (ids.length > 0) {
var id = ids.splice(0,1)[0];
refToTable.child(id).once('value', function(snapshot) {
rows.push(snapshot.val());
});
}
callback(rows);
}
Note that the above should probably be recursive, so use it for inspiration and not as copy/paste code.
Another (and probably better way) to solve the problem is by figuring out why these three rows are selected and why not others. These rows probably have something in common. Once you know what they have in common, you can model that into the data structure.
Update (20160408): for a good explanation of why the above is a lot faster on Firebase than you might expect, see this answer.

asp.net entity framework - Complicated Queries with join + Membership user

I have 2 tables.
Users - have userID, userMainGroup and userMinorGroup
Tasks - TaskId, UserId
My goal is:
I have current CurrentuserId and i want to show him all the tasks that were created by users from the same MainGroup as he.
In SQL i would write:
Select *
From Tasks Left join Users on tasks.Id=users.id
Where users.MainGroup=CurrentuserMainGroup; (var)
How do i do it using entity framework?
I understood that to make a join i need to write something like:
var tasks = from t in db.tasks
from u in db.users
where t.Id=u.Id
select new {t.Id, t.name....}
but where do i put the condition Where on the MainGroup?
you can try like this
var data= (from con in db.tasks
let UserMainGroup = db.users.where(x=>x.id==con.id).FirstOrDefault()
where UserMainGroup.MainGroup=CurrentuserMainGroup
select new {
ID=con.id,
Name=con.name
}).ToList();
i think this will help you.......
It is recommended that you use navigation properties in stead of manually coded joins:
from t in db.Tasks
where t.User.MainGroup == currentuserMainGroup
select new {t.Id, t.name.... , t.User.Name, ... }

Resources