Fix entity framework queries to work in netcoreapp3.0

This commit is contained in:
nicolas.dorier
2019-10-06 15:47:46 +09:00
parent f4977e7f9f
commit 536f98b566
6 changed files with 20 additions and 14 deletions

View File

@@ -3037,7 +3037,8 @@ noninventoryitem:
private static bool IsMapped(Invoice invoice, ApplicationDbContext ctx) private static bool IsMapped(Invoice invoice, ApplicationDbContext ctx)
{ {
var h = BitcoinAddress.Create(invoice.BitcoinAddress, Network.RegTest).ScriptPubKey.Hash.ToString(); var h = BitcoinAddress.Create(invoice.BitcoinAddress, Network.RegTest).ScriptPubKey.Hash.ToString();
return ctx.AddressInvoices.FirstOrDefault(i => i.InvoiceDataId == invoice.Id && i.GetAddress() == h) != null; return (ctx.AddressInvoices.Where(i => i.InvoiceDataId == invoice.Id).ToArrayAsync().GetAwaiter().GetResult())
.Where(i => i.GetAddress() == h).Any();
} }
} }
} }

View File

@@ -26,6 +26,7 @@ using Newtonsoft.Json;
namespace BTCPayServer.Controllers namespace BTCPayServer.Controllers
{ {
[Filters.BitpayAPIConstraint(false)]
public partial class InvoiceController : Controller public partial class InvoiceController : Controller
{ {
InvoiceRepository _InvoiceRepository; InvoiceRepository _InvoiceRepository;

View File

@@ -31,7 +31,7 @@ namespace BTCPayServer.HostedServices
internal override Task[] InitializeTasks() internal override Task[] InitializeTasks()
{ {
return new[] return new Task[]
{ {
CreateLoopTask(RefreshCoinAverageSupportedExchanges), CreateLoopTask(RefreshCoinAverageSupportedExchanges),
CreateLoopTask(RefreshCoinAverageSettings), CreateLoopTask(RefreshCoinAverageSettings),

View File

@@ -79,7 +79,7 @@ namespace BTCPayServer.Hosting
// StyleSrc = "'self' 'unsafe-inline'", // StyleSrc = "'self' 'unsafe-inline'",
// ScriptSrc = "'self' 'unsafe-inline'" // ScriptSrc = "'self' 'unsafe-inline'"
//}); //});
}).AddControllersAsServices(); }).AddNewtonsoftJson().AddControllersAsServices();
services.TryAddScoped<ContentSecurityPolicies>(); services.TryAddScoped<ContentSecurityPolicies>();
services.Configure<IdentityOptions>(options => services.Configure<IdentityOptions>(options =>
{ {
@@ -255,10 +255,14 @@ namespace BTCPayServer.Hosting
forwardingOptions.ForwardedHeaders = ForwardedHeaders.All; forwardingOptions.ForwardedHeaders = ForwardedHeaders.All;
app.UseForwardedHeaders(forwardingOptions); app.UseForwardedHeaders(forwardingOptions);
#if !NETCOREAPP21 #if !NETCOREAPP21
app.UsePayServer();
app.UseRouting(); app.UseRouting();
#endif #endif
app.UseCors(); app.UseCors();
#if NETCOREAPP21
app.UsePayServer(); app.UsePayServer();
#endif
app.UseStaticFiles(); app.UseStaticFiles();
app.UseProviderStorage(options); app.UseProviderStorage(options);
app.UseAuthentication(); app.UseAuthentication();

View File

@@ -103,7 +103,7 @@ namespace BTCPayServer.Security.Bitpay
{ {
using (StreamReader reader = new StreamReader(httpContext.Request.Body, Encoding.UTF8, true, 1024, true)) using (StreamReader reader = new StreamReader(httpContext.Request.Body, Encoding.UTF8, true, 1024, true))
{ {
body = reader.ReadToEnd(); body = await reader.ReadToEndAsync();
} }
httpContext.Request.Body.Position = 0; httpContext.Request.Body.Position = 0;
} }

View File

@@ -86,12 +86,12 @@ retry:
using (var db = _ContextFactory.CreateContext()) using (var db = _ContextFactory.CreateContext())
{ {
return (await db.AddressInvoices return (await db.AddressInvoices
.Include(a => a.InvoiceData.Payments)
.Include(a => a.InvoiceData.RefundAddresses)
#pragma warning disable CS0618 #pragma warning disable CS0618
.Where(a => addresses.Contains(a.Address)) .Where(a => addresses.Contains(a.Address))
#pragma warning restore CS0618 #pragma warning restore CS0618
.Select(a => a.InvoiceData) .Select(a => a.InvoiceData)
.Include(a => a.Payments)
.Include(a => a.RefundAddresses)
.ToListAsync()).Select(ToEntity); .ToListAsync()).Select(ToEntity);
} }
} }
@@ -491,13 +491,13 @@ retry:
if (queryObject.InvoiceId != null && queryObject.InvoiceId.Length > 0) if (queryObject.InvoiceId != null && queryObject.InvoiceId.Length > 0)
{ {
var statusSet = queryObject.InvoiceId.ToHashSet(); var statusSet = queryObject.InvoiceId.ToHashSet().ToArray();
query = query.Where(i => statusSet.Contains(i.Id)); query = query.Where(i => statusSet.Contains(i.Id));
} }
if (queryObject.StoreId != null && queryObject.StoreId.Length > 0) if (queryObject.StoreId != null && queryObject.StoreId.Length > 0)
{ {
var stores = queryObject.StoreId.ToHashSet(); var stores = queryObject.StoreId.ToHashSet().ToArray();
query = query.Where(i => stores.Contains(i.StoreDataId)); query = query.Where(i => stores.Contains(i.StoreDataId));
} }
@@ -508,8 +508,8 @@ retry:
if (!string.IsNullOrEmpty(queryObject.TextSearch)) if (!string.IsNullOrEmpty(queryObject.TextSearch))
{ {
var ids = new HashSet<string>(SearchInvoice(queryObject.TextSearch)); var ids = new HashSet<string>(SearchInvoice(queryObject.TextSearch)).ToArray();
if (ids.Count == 0) if (ids.Length == 0)
{ {
// Hacky way to return an empty query object. The nice way is much too elaborate: // Hacky way to return an empty query object. The nice way is much too elaborate:
// https://stackoverflow.com/questions/33305495/how-to-return-empty-iqueryable-in-an-async-repository-method // https://stackoverflow.com/questions/33305495/how-to-return-empty-iqueryable-in-an-async-repository-method
@@ -526,18 +526,18 @@ retry:
if (queryObject.OrderId != null && queryObject.OrderId.Length > 0) if (queryObject.OrderId != null && queryObject.OrderId.Length > 0)
{ {
var statusSet = queryObject.OrderId.ToHashSet(); var statusSet = queryObject.OrderId.ToHashSet().ToArray();
query = query.Where(i => statusSet.Contains(i.OrderId)); query = query.Where(i => statusSet.Contains(i.OrderId));
} }
if (queryObject.ItemCode != null && queryObject.ItemCode.Length > 0) if (queryObject.ItemCode != null && queryObject.ItemCode.Length > 0)
{ {
var statusSet = queryObject.ItemCode.ToHashSet(); var statusSet = queryObject.ItemCode.ToHashSet().ToArray();
query = query.Where(i => statusSet.Contains(i.ItemCode)); query = query.Where(i => statusSet.Contains(i.ItemCode));
} }
if (queryObject.Status != null && queryObject.Status.Length > 0) if (queryObject.Status != null && queryObject.Status.Length > 0)
{ {
var statusSet = queryObject.Status.ToHashSet(); var statusSet = queryObject.Status.ToHashSet().ToArray();
query = query.Where(i => statusSet.Contains(i.Status)); query = query.Where(i => statusSet.Contains(i.Status));
} }