Tvde1
Tvde1
CC#
Created by nathanAjacobs on 10/6/2024 in #help
Is it necessary to setup validation constraints at the api level and database level?
Unique constraints on database level are still useful for concurrency issues or if a bug in the business logic exists
6 replies
CC#
Created by Julian on 7/17/2024 in #help
Hook into job state change in HangFire
Just curious, what do you want to achieve with this?
6 replies
CC#
Created by Adam on 6/27/2024 in #help
Making my functions more generic
you have your ) a bit misplaced
return statsDB.Stats
.Where(s => s.PrimaryTags.Contains(tagName))
.ToList();
return statsDB.Stats
.Where(s => s.PrimaryTags.Contains(tagName))
.ToList();
24 replies
CC#
Created by Adam on 6/27/2024 in #help
Making my functions more generic
It's a bit strange why there would be things missing but alright 😁
24 replies
CC#
Created by Adam on 6/27/2024 in #help
Making my functions more generic
This one is fine
24 replies
CC#
Created by Adam on 6/27/2024 in #help
Making my functions more generic
if you wanted to, it would look something like
interface ITaggable
{
public string TagName { get; }
public string Name { get; }
}

public Dictionary<string, T> StatsWithTag<T>(DbSet<T> dbSet, string tagName)
{
return dbSet
.Where(stat => stat.TagName == tagName)
.ToDictionary(stat => stat.Name);
}

class Stat : ITaggable
{
// your properties
public string StatName { get; set; }
...

// required because of the interface
public string TagName { get; }

// Required so the interface can get the name
public string Name => StatName;
}

class SomethingElse : ITaggable
{
// your properties
public string MySomethingName { get; set; }
...

// required because of the interface
public string TagName { get; }

// Required so the interface can get the name
public string Name => MySomethingName;
}
interface ITaggable
{
public string TagName { get; }
public string Name { get; }
}

public Dictionary<string, T> StatsWithTag<T>(DbSet<T> dbSet, string tagName)
{
return dbSet
.Where(stat => stat.TagName == tagName)
.ToDictionary(stat => stat.Name);
}

class Stat : ITaggable
{
// your properties
public string StatName { get; set; }
...

// required because of the interface
public string TagName { get; }

// Required so the interface can get the name
public string Name => StatName;
}

class SomethingElse : ITaggable
{
// your properties
public string MySomethingName { get; set; }
...

// required because of the interface
public string TagName { get; }

// Required so the interface can get the name
public string Name => MySomethingName;
}
than you can do
var statsByName = StatsWithTag(statsDB.Stats, "my-tag");
var othersByName = StatsWithTag(statsDB.SomethingElse, "my-other-tag");
var statsByName = StatsWithTag(statsDB.Stats, "my-tag");
var othersByName = StatsWithTag(statsDB.SomethingElse, "my-other-tag");
But I wouldn't make it more complicated than it needs to be
24 replies
CC#
Created by Adam on 6/27/2024 in #help
Making my functions more generic
for your use case I wouldn't deduplicate it
24 replies
CC#
Created by Adam on 6/27/2024 in #help
Making my functions more generic
only when you do * ToList() * ToDictionary() * First() etc, does your query get executed. So any .Where() that you do, will be translated to SQL for better performance
24 replies
CC#
Created by Adam on 6/27/2024 in #help
Making my functions more generic
it is a little bit complicated, but in this case, the LINQ is more performant. Your example does: 1. Get all Stats from the database 2. Loop over all the stats 3. If it matches the tag name, add to dictionary The example I showed uses IQueryable, which entity framework is built on to do the following 1. Only take from the database, all the Stats which match the tag name. (This will do the query:
SELECT * FROM Stats
WHERE TagName = 'your-tag-name'
SELECT * FROM Stats
WHERE TagName = 'your-tag-name'
2. it loops over only the results which are found and makes a dictionary
24 replies
CC#
Created by Adam on 6/27/2024 in #help
Making my functions more generic
and it is recommended to make this async, but I will leave this up to you
24 replies
CC#
Created by Adam on 6/27/2024 in #help
Making my functions more generic
a better way to do this is:
public Dictionary<string, Stat> StatsWithTag(string tagName)
{
return statsDB.Stats
.Where(stat => stat.TagName == tagName)
.ToDictionary(stat => stat.StatName);
}
public Dictionary<string, Stat> StatsWithTag(string tagName)
{
return statsDB.Stats
.Where(stat => stat.TagName == tagName)
.ToDictionary(stat => stat.StatName);
}
I believe this gives the same result
24 replies
CC#
Created by Adam on 6/27/2024 in #help
Making my functions more generic
could you show us the functions? I would define an interface which has the property that it needs from both, and then you can do
public Task DoSomething<TEntity>(TEntity entity)
where TEntity : INeeded
{
entity.Id = ...;
}

interface TEntity
{
public int Id { get; }
}
public Task DoSomething<TEntity>(TEntity entity)
where TEntity : INeeded
{
entity.Id = ...;
}

interface TEntity
{
public int Id { get; }
}
24 replies
CC#
Created by Sekoree on 6/21/2024 in #help
Every HttpClient request has a 5 second delay before execution
At first glance it does look like a slow api. Can you use postman or so to verify the api response time? Otherwise i would look into it avalonia does async await in a different way where there would be time spent waiting You could also do a profiling session
29 replies
CC#
Created by Tvde1 on 6/3/2024 in #help
dotnet test on Azure Devops has .NET 8 and requires .NET 6 and crashes?
To my knowledge, if you install .NET 8, it installs .NET 6 too, right?
8 replies
CC#
Created by Tvde1 on 6/3/2024 in #help
dotnet test on Azure Devops has .NET 8 and requires .NET 6 and crashes?
Yes
8 replies
CC#
Created by Tvde1 on 6/3/2024 in #help
dotnet test on Azure Devops has .NET 8 and requires .NET 6 and crashes?
I'm going to try with:
- task: DotNetCoreCLI@2
displayName: 'Test assemblies'
inputs:
command: 'test'
projects: '**/*.Test.csproj'
arguments: '--configuration $(buildConfiguration)'
- task: DotNetCoreCLI@2
displayName: 'Test assemblies'
inputs:
command: 'test'
projects: '**/*.Test.csproj'
arguments: '--configuration $(buildConfiguration)'
8 replies
CC#
Created by Tvde1 on 6/3/2024 in #help
dotnet test on Azure Devops has .NET 8 and requires .NET 6 and crashes?
For context, the .runsettings file is:
<RunSettings>
<!-- Configurations that affect the Test Framework -->
<RunConfiguration>
<!-- Path relative to solution directory -->
<TargetPlatform>x64</TargetPlatform>
<TreatNoTestsAsError>true</TreatNoTestsAsError>
</RunConfiguration>
<MSTest>
<TreatNoTestsAsError>true</TreatNoTestsAsError>
<MaxCpuCount>0</MaxCpuCount>
<MapInconclusiveToFailed>True</MapInconclusiveToFailed>
</MSTest>
</RunSettings>
<RunSettings>
<!-- Configurations that affect the Test Framework -->
<RunConfiguration>
<!-- Path relative to solution directory -->
<TargetPlatform>x64</TargetPlatform>
<TreatNoTestsAsError>true</TreatNoTestsAsError>
</RunConfiguration>
<MSTest>
<TreatNoTestsAsError>true</TreatNoTestsAsError>
<MaxCpuCount>0</MaxCpuCount>
<MapInconclusiveToFailed>True</MapInconclusiveToFailed>
</MSTest>
</RunSettings>
Not sure why this exists, but this does not mention any .NET version
8 replies
CC#
Created by skmkqw on 5/14/2024 in #help
Cant create seed data for integrational tests
https://github.com/search?q=repo%3Adotnet%2FAspNetCore.Docs.Samples%20InitializeDbForTests&type=code you could check out this repo, they don't do seeding in the configure method
12 replies
CC#
Created by skmkqw on 5/14/2024 in #help
Cant create seed data for integrational tests
not sure if the in memory db gets recreated or so
12 replies
CC#
Created by skmkqw on 5/14/2024 in #help
Cant create seed data for integrational tests
hmm all I can think of now is that Utilities.InitializeDatabase(dbContext, userManager); is called inside the ConfigureTestServices. Maybe you would want to do it after
12 replies