question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Support for IQueryable<TEntity> as data source for UpsertRange<TEntity>?

See original GitHub issue

I am faced with a scenario where it would be super desireable to be able to pass an IQueryable<TEntity> to UpsertRange<TEntity> instead of an IEnumerable<TEntity> or TEntity[].

This should then result in the UPSERT being run entirely on the DB side as opposed to loading entities into memory. I.e.:

var someSourceEntitiesProjectionToDailyVisits = dataContext.SomeSourceEntities
    .Where(x => x.SomeSourceEntityProperty == someValue)
    .Select(x => new {
        UserID = x.SomeFieldMatchedToUserId,
        Date = DateTime.UtcNow.Date
    });

dataContext.DailyVisits
    .UpsertRange(someSourceEntitiesProjectionToDailyVisits)
    .On(v => new { v.UserID, v.Date })
    .WhenMatched(v => new DailyVisit
    {
        Visits = v.Visits + 1,
    })
    .RunAsync();

Is something like this on the roadmap?

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:8 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
APIWTcommented, Feb 25, 2019

Okay, this totally makes sense to me now. It is similar to the INSERT INTO … SELECT … ON DUPLICATE KEY UPDATE pattern that I grew to love in MySQL. I am not sure what it will take to implement something like this so I’ll let @artiomchi take it from here. Sorry I could not be more helpful 😦

0reactions
artiomchicommented, Feb 28, 2021

Going to close this issue due to inactivity. Also, as explained above - this is too much outside the scope of this project

Read more comments on GitHub >

github_iconTop Results From Across the Web

How can I return IQueryable<TEntity> object from a mock ...
Unless your business logic actually creates an implementation of IQueryable<T> then you want to return a mock stub object.
Read more >
IQueryable Interface (System.Linq)
Provides functionality to evaluate queries against a specific data source wherein the type of the data is not specified.
Read more >
Supported and Unsupported LINQ Methods (LINQ to Entities)
This article summarizes the standard query operators that are supported and unsupported in LINQ to Entities queries.
Read more >
IEnumerable VS IQueryable
IEnumerable doesn't support custom query. ... queries over local collection objects and remote data sources like SQL, XML documents, etc.
Read more >
The Difference Between IEnumerable and IQueryable Explained
The Users class is a stand in for the Users database table. The Users data doesn't exist in our app. In order to...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found