Scottek utek
Scottek utek
CC#
Created by Scottek utek on 10/28/2023 in #help
✅ entity framework return all objects
Hello, If I use entity framework and I want to get all objects in my repository, what should I do? 1:
private IEnumerable<TrainName> GetTrainNames()
{
return _dbStorage.TrainNames;
}
private IEnumerable<TrainName> GetTrainNames()
{
return _dbStorage.TrainNames;
}
2:
private async Task<IEnumerable<TrainName>> GetTrainNames()
{
return await _dbStorage.TrainNames.ToListAsync();
}
private async Task<IEnumerable<TrainName>> GetTrainNames()
{
return await _dbStorage.TrainNames.ToListAsync();
}
Or something else?
8 replies
CC#
Created by Scottek utek on 6/27/2023 in #help
❔ Random error in ASP.NET (Could not load file or assembly 'System.Transactions.Local)
8 replies
CC#
Created by Scottek utek on 6/22/2023 in #help
❔ ✅ custom mapper and resolvers
Hello, I've been trying to use automapper for a while, but now I've decided to just replace it with my own mapping methods, I've created static extension class, but there is one problem with it. Mapping class is now static, but my resolvers classed need to dependency inject services to work, how I am supposed to call my resolver in static class? MappingExtensions:
public static class MappingExtensions
{
public static PublicAd MapToPublicAd(this Ad ad, User user)
{
return new PublicAd
{
Claimed = ad.Claimed,
Distance = // I don't know
};
}
...
public static class MappingExtensions
{
public static PublicAd MapToPublicAd(this Ad ad, User user)
{
return new PublicAd
{
Claimed = ad.Claimed,
Distance = // I don't know
};
}
...
DistanceResolver:
public class DistanceResolver
{
private readonly IDistanceService _distanceService;

public DistanceResolver(IDistanceService distanceService)
{
_distanceService = distanceService;
}

public double Resolve(Ad ad, User user)
{
if (user is null)
{
throw new ArgumentException($"No valid user passed to");
}

if (user.Municipality is null || source.Municipality is null)
{
return -1d;
}

return _distanceService.GetDistanceInKm(
ad.Municipality.Location!.Y,
ad.Municipality.Location!.X,
user.Municipality.Location!.Y,
user.Municipality.Location!.X
);
}
}
public class DistanceResolver
{
private readonly IDistanceService _distanceService;

public DistanceResolver(IDistanceService distanceService)
{
_distanceService = distanceService;
}

public double Resolve(Ad ad, User user)
{
if (user is null)
{
throw new ArgumentException($"No valid user passed to");
}

if (user.Municipality is null || source.Municipality is null)
{
return -1d;
}

return _distanceService.GetDistanceInKm(
ad.Municipality.Location!.Y,
ad.Municipality.Location!.X,
user.Municipality.Location!.Y,
user.Municipality.Location!.X
);
}
}
14 replies
CC#
Created by Scottek utek on 4/24/2023 in #help
❔ AmazonS3Client problems
10 replies
CC#
Created by Scottek utek on 3/19/2023 in #help
✅ jwt authentication always returns 401
I'm trying to build a backend with .net & firebase, but I can not get over one specific problem. When I try to implement jwt, calling any endpoint just throws 401 error code (after logging in in swagger ofc). What am I doing wrong?
42 replies
CC#
Created by Scottek utek on 3/4/2023 in #help
❔ EntityFramework migrations PostgreSQL
I've been trying to set up migration in .NET, I have auto-generated migrate files, but there are some problems with it. When I try to execute this piece code:
modelBuilder
.HasAnnotation("Npgsql:CollationDefinition:insensitive_collation", "en-u-ks-primary,en-u-ks-primary,icu,")
.HasAnnotation("Relational:MaxIdentifierLength", 63)
.HasAnnotation("ProductVersion", "5.0.4")
.HasAnnotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn);
modelBuilder
.HasAnnotation("Npgsql:CollationDefinition:insensitive_collation", "en-u-ks-primary,en-u-ks-primary,icu,")
.HasAnnotation("Relational:MaxIdentifierLength", 63)
.HasAnnotation("ProductVersion", "5.0.4")
.HasAnnotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn);
It says: 42P17: parameter "locale" must be specified. How should I edit "en-u-ks-primary,en-u-ks-primary,icu," to fix it? I'm using entity-framework 5.0.7
13 replies
CC#
Created by Scottek utek on 8/17/2022 in #help
how to format multiple conditions assignments in return statement [CLOSED] [Answered]
Greetings, I was wondering, how could I properly format this piece of code.
return
res > PageCount ?
-1
:
isLastPage ?
resint > PageItemCount(ItemCount / ItemsPerPage) ?
-1
:
resint
: resint;
return
res > PageCount ?
-1
:
isLastPage ?
resint > PageItemCount(ItemCount / ItemsPerPage) ?
-1
:
resint
: resint;
You can see I tried to format it somehow, but I don't think it looks good. :D
21 replies