C
C#2y ago
Vinicius

❔ rename tuple

public async Task<(List<SalesReportEntity>, int totalSales)> GetAllSalesReportAsync(int companyId, int? SalesPage, int? Limitpage, DateTime? StartDate, DateTime? EndDate)
{
return (sales, sales.Count());
}
obs: I cut off some lines
public async Task<(List<SalesReportEntity>, int totalSales)> GetAllSalesReportAsync(int companyId, int? SalesPage, int? Limitpage, DateTime? StartDate, DateTime? EndDate)
{
return (sales, sales.Count());
}
obs: I cut off some lines
is returning item1: [{…}] item2: 1 How can I rename it to sales and totalSales
16 Replies
Angius
Angius2y ago
I'd probably just use a record here instead of a tuple But return (sales: sales, totalSales: sales.Count()) should work With the return type being Task<(List<SalesReportEntity> sales, int totalSales)>
sibber
sibber2y ago
this not necessary actually, if you specify the names in the return type
Vinicius
Vinicius2y ago
public async Task<(List<SalesReportEntity>allSales, int totalSales)> GetAllSalesReportAsync(){
return (allSales: sales, totalSales: sales.Count());
}
public async Task<(List<SalesReportEntity>allSales, int totalSales)> GetAllSalesReportAsync(){
return (allSales: sales, totalSales: sales.Count());
}
wont change :-:
Vinicius
Vinicius2y ago
MODiX
MODiX2y ago
Cyberrex#8052
REPL Result: Success
System.Text.Json.JsonSerializer.Serialize((allSales: 1, totalSales: 2), new JsonSerializerOptions { IncludeFields = true })
System.Text.Json.JsonSerializer.Serialize((allSales: 1, totalSales: 2), new JsonSerializerOptions { IncludeFields = true })
Result: string
{"Item1":1,"Item2":2}
{"Item1":1,"Item2":2}
Compile: 444.748ms | Execution: 52.984ms | React with ❌ to remove this embed.
sibber
sibber2y ago
huh
Angius
Angius2y ago
I guess STJ doesn't serialize named tuples Thankfully, solution is simple: just use a record
Vinicius
Vinicius2y ago
you right
Vinicius
Vinicius2y ago
Vinicius
Vinicius2y ago
return new SalesResume(sales, sales.Count());
Vinicius
Vinicius2y ago
idk if I did best way
Angius
Angius2y ago
I'd just keep the record next to the method tbh, no need to make a whole separate file for it But, sure, it works either way
Vinicius
Vinicius2y ago
Interface need to be typed as well
namespace Epilefinho.Domain.Repositories
{
public interface ISaleRepository
{

Task<SalesResume> GetAllSalesReportAsync(int idCompany, int? NumberPage, int? Limitpage, DateTime? StartDate, DateTime? EndDate);

}
}
namespace Epilefinho.Domain.Repositories
{
public interface ISaleRepository
{

Task<SalesResume> GetAllSalesReportAsync(int idCompany, int? NumberPage, int? Limitpage, DateTime? StartDate, DateTime? EndDate);

}
}
I'd prefer but I couldnt
Angius
Angius2y ago
Yeah, understandable
Vinicius
Vinicius2y ago
thanks
Accord
Accord2y ago
Was this issue resolved? If so, run /close - otherwise I will mark this as stale and this post will be archived until there is new activity.
Want results from more Discord servers?
Add your server
More Posts
Search generic list for a searchwordHeeelp! deadline soon and i'm stuck.. I have a list like this: List<string[]> blogPostList = new()Remove or overwrite single element of list of arrays(not completely sure its called list of arrays) Basically i have one of these: List<string[]> blog✅ When calling a generic function, how can I tell it that I'm going to be passing null?I've got a generic function which is something like this: ```cs public ReturnType GetValue<ReturnTyp❔ WPF Textbox decimal onlyHello, i'd like to know how we are supposed to configure our textbox in order to accept only decimalmaui deserialize problemI am having a problem when trying to deserialize api data ```C# string content = await response.C❔ Log from helper class without creating new context? (Serilog)I have a bunch of services with their own dedicated loggers that have config'd settings for filterin❔ Swagger Open API not showing Request examples in the UII've written an Azure Function with Open API in C#, but when I open up the Swagger/UI to test my AzuLooking solution for get query from _dbContext.SaveChangesAsync() for save logs and easier debuggingHello, i have a .net core 6.0 app that save entites in MSSQL database with EfCORE 6.0 so my function❔ I'm building an MVC core webshop. How should I be structuring controllers, actions and views?So, right now, I have one single view, and this view renders both information about the product and ❔ How to make an object follows my mouse?so I am new at programming and trying to make a top down shooting games in windows form app. My lect