Dropps
Dropps
CC#
Created by Dropps on 7/2/2023 in #help
❔ EF core querying issue
7 replies
CC#
Created by Dropps on 6/29/2023 in #help
❔ simplification
iam wondering if there is a way to simplify following example for readability using linq
object outerobject = new();
object apiData = new();
foreach (ObjectX x in apiData.Keys)
{
foreach (List<ObjectY> yList in apiData.Values)
{
outerobject.Components.Add(new Components
{
property = x,
propertyList = x
});
}
}
object outerobject = new();
object apiData = new();
foreach (ObjectX x in apiData.Keys)
{
foreach (List<ObjectY> yList in apiData.Values)
{
outerobject.Components.Add(new Components
{
property = x,
propertyList = x
});
}
}
15 replies
CC#
Created by Dropps on 6/27/2023 in #help
❔ efcore querying
hello there iam right now digging a bit deeper into ef core and how to query data correctly but i dont get my head around something maybe someone can help i have following data classes:
namespace ExampleApp.Tests.Application.Models;

public class Product
{
/// <summary>
/// Unique identifier for the Product.
/// </summary>
public Guid Id { get; set; }

/// <summary>
/// Name of the Product.
/// </summary>
public string Name { get; set; } = string.Empty;

/// <summary>
/// Description of the Product.
/// </summary>
public string? Description { get; set; }

/// <summary>
/// Price of the Product.
/// </summary>
public decimal Price { get; set; }

/// <summary>
/// Average rating of the Product.
/// </summary>
public float? Rating { get; set; }

/// <summary>
/// Rating of the Product by the user.
/// </summary>
public int? UserRating { get; set; }
}
namespace ExampleApp.Tests.Application.Models;

public class Product
{
/// <summary>
/// Unique identifier for the Product.
/// </summary>
public Guid Id { get; set; }

/// <summary>
/// Name of the Product.
/// </summary>
public string Name { get; set; } = string.Empty;

/// <summary>
/// Description of the Product.
/// </summary>
public string? Description { get; set; }

/// <summary>
/// Price of the Product.
/// </summary>
public decimal Price { get; set; }

/// <summary>
/// Average rating of the Product.
/// </summary>
public float? Rating { get; set; }

/// <summary>
/// Rating of the Product by the user.
/// </summary>
public int? UserRating { get; set; }
}
namespace ExampleApp.Tests.Application.Models;

public class ProductRating
{
/// <summary>
/// Unique identifier for the Product.
/// </summary>
public required Guid ProductId { get; init; }

/// <summary>
/// Unique identifier for the user.
/// </summary>
public required Guid UserId { get; init; }

/// <summary>
/// Rating of the Product by the user. 1-5.
/// </summary>
public required int Rating { get; init; }

/// <summary>
/// Comment on the Product by the user.
/// </summary>
public required string? Comment { get; init; }
}
namespace ExampleApp.Tests.Application.Models;

public class ProductRating
{
/// <summary>
/// Unique identifier for the Product.
/// </summary>
public required Guid ProductId { get; init; }

/// <summary>
/// Unique identifier for the user.
/// </summary>
public required Guid UserId { get; init; }

/// <summary>
/// Rating of the Product by the user. 1-5.
/// </summary>
public required int Rating { get; init; }

/// <summary>
/// Comment on the Product by the user.
/// </summary>
public required string? Comment { get; init; }
}
i have a table for both of these classes now my question is how do i handle following behaviour: GetAllAsync(Guid? userId) GetByIdAsync(Guid productId, Guid? userId) goal is to include the rating the user gove if the userid isnt null if it is then return just the product model but i dont get around how to do it this is what i tried
public async Task<Product?> GetByIdAsync(Guid id, Guid? userId = null, CancellationToken token = default)
{
if (userId == null)
{
return await _dbContext.Products.FindAsync(new object?[] { id }, cancellationToken: token);
}

return await _dbContext.Products
.Include(f => f.Rating)
.FirstOrDefaultAsync(f => f.Id == id, cancellationToken: token);
}
public async Task<Product?> GetByIdAsync(Guid id, Guid? userId = null, CancellationToken token = default)
{
if (userId == null)
{
return await _dbContext.Products.FindAsync(new object?[] { id }, cancellationToken: token);
}

return await _dbContext.Products
.Include(f => f.Rating)
.FirstOrDefaultAsync(f => f.Id == id, cancellationToken: token);
}
44 replies
CC#
Created by Dropps on 6/25/2023 in #help
❔ efcore and repositorys
in what scenarios does it make sense to use repositorys withhin ef core? i have a api layer project and a application layer project now my question is do i expose the dbcontext to the api project directly or should i introduce a repository pattern? i generally dont think it makes much sense to use repositorys as efcore basically has its own implementation for that with the DbSet<T> classes what are your suggestions?
71 replies
CC#
Created by Dropps on 6/11/2023 in #help
✅ System.NotSupportedException with EF Core
quick question:
public async Task<List<Order>> GetAllOrders()
{
return await _dbContext.Orders
.Include(o => o.OrderFoods!)
.ThenInclude(of => of.Food)
.ToListAsync();
}
public async Task<List<Order>> GetAllOrders()
{
return await _dbContext.Orders
.Include(o => o.OrderFoods!)
.ThenInclude(of => of.Food)
.ToListAsync();
}
gives me a NotSupportedException but how do i fix that? dataclass:
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;

#pragma warning disable CS8618
namespace iFoodTracker.Models;

public class Order
{
[Key]
[DatabaseGenerated(DatabaseGeneratedOption.Identity)]
public Guid Id { get; set; }
public DateTime CreatedAt { get; set; }
public bool PaidStatus { get; set; }
public string UserId { get; set; }
public string? EmployeeShort { get; set; }
public IEnumerable<OrderFood>? OrderFoods { get; set; }
}
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;

#pragma warning disable CS8618
namespace iFoodTracker.Models;

public class Order
{
[Key]
[DatabaseGenerated(DatabaseGeneratedOption.Identity)]
public Guid Id { get; set; }
public DateTime CreatedAt { get; set; }
public bool PaidStatus { get; set; }
public string UserId { get; set; }
public string? EmployeeShort { get; set; }
public IEnumerable<OrderFood>? OrderFoods { get; set; }
}
25 replies
CC#
Created by Dropps on 1/6/2023 in #help
❔ Icons in WPF
hello there how do i get my application to use icons? i created relative pathings to my svg files for the <Window> itself but it says then it could not find it second issue is how do i get those svgs displayed as images somewhere? saving them as relative paths also doesnt work
2 replies
CC#
Created by Dropps on 12/29/2022 in #help
✅ BenchmarkDotNet Error with Windows Defender
14 replies
CC#
Created by Dropps on 10/6/2022 in #help
creating a HostProcess to control other apps
Hello there, iam working on a bigger project needing following sooner or later for both things but iam alrdy curios on how i should proceed when building a application wich is run by a "host" process (responsible for loading in resources and configuring env variables for the referenced projects that need that and to be able to start and close the app) basicly the host process is supposed to run both apps (a dashboard and a launcher) wich are 2 diffrent wpf apps then also be able to create a "playground" for my plugin system wich can also be extending wpf apps meaning window in window apps whats the best way of achiveing that? i searched around online already but found nothing better than "Process.Start(blah)" but that doesnt give full control over the application
26 replies
CC#
Created by Dropps on 10/2/2022 in #help
New ConsoleApplication unable to reference WPF apps.
4 replies
CC#
Created by Dropps on 10/2/2022 in #help
AppBuilder class
hello there iam currently trying to think of a solution so i can make myself a AppBuilder without needing to reference all projects directly basicly i have a Program.cs from a wpf app in Project B but in project A i want to be able to say something like
cs
builder.AddSingleton<LoggerForProjectA>();
cs
builder.AddSingleton<LoggerForProjectA>();
how could that be done?
34 replies
CC#
Created by Dropps on 9/20/2022 in #help
Python to CS entrypoint
how can i compile a python package into a dll or so and use it withhin c# ? or have both languages coexisting?
15 replies
CC#
Created by Dropps on 9/18/2022 in #help
Project Structure
14 replies
CC#
Created by Dropps on 9/17/2022 in #help
Right way to use Interfaces in Large Scale Blazor Server Web Applications
Hello there, iam currently working on a <see title> app for something iam not allowed to leak now iam wondering how to use Interfaces correctly? I used them to make Contracts for Models or similar. But today i looked through some Templates we could potentionally use and i often see in the pages with code behind files the term
[Inject]
public InterfaceName _interface { get; set; }

...

_interface.SomeMethod()
[Inject]
public InterfaceName _interface { get; set; }

...

_interface.SomeMethod()
but iam not at all sure what to use that for or how its supposed to work as Interfaces dont have any kind of function bodys anyone can give a conclusion or so? ive also searched about it in StackExchange and StackOverflow but both times likely 0 results for this exact use case. Edit: please ping me when you have a solution or similar i doubt i will watch this actively as its pretty a big server i cant read every message
28 replies