C#

C

C#

We are a programming server aimed at coders discussing everything related to C# (CSharp) and .NET.

Join

Ef core rogue key autogeneration

I am lost, 3 hours down i can't seem to find why entity decides to create a insert on a autogenerated column. The list initiation is a ugly mess but its a temporary seeder to iron out the kinks of the schema. When i inspect the migration, the column has been marked with Identity, (1,1). I added the fluent api as a last resort. But at this point I'm clueless. print screens are partial, omitted for brevity, can send full if nessecary....
No description

✅ Anonymous and lambda function in C#

Hello guys, I was just reading a bit about lambda functions. From what I've understood, it's an inline style of declaring a function definition. We use it if for example we want to only execute a function once. They are used together with delegates, to store the function reference and just invoke the function as needed. Lambda function relies on delegates to work? E.g of lambda functions:...

Keyboard shortcuts always resetting after restart

I always have to set my keyboard shortcut for some reason can anyone help?

✅ Enums in C#

Hello guys, I'm learning about what an "enum" is, I often saw this word several times without really understanding what it is or how it works. So from what I've read, an enum is a distinct value type which represents a set of constants. We declare one as follows:...

✅ Delegates in C#

Hello guys, I just read a bit about delegates in C#, can someone confirm whether the following statements are correct and would really appreciate if you guys can add to those statements if needed (like any things I missed). So, what I've understood, is that a delegate is just a type that stores a reference to a method. if we declare a delegate method like this:...

Entity Framework Core updating tables in navigation fields

so in efcore lets say i have an entity Foo and Baz: ``` public class Foo { public int Id {get;set;}...

Fast regex that takes in a span instead of a string

I'm trying to port a lexer I wrote in c++ to c# and want to get the same functionality as RE2's consume method, however it seems like all the c# wrappers for RE2 don't even support using ReadOnlySpan<char> instead of strings as input, which seems like it would be ludicrously slow when ran repeatedly compared to using a ReadOnlySpan<char> (or equivalent to c++'s string_view). Is there a way around this or am I forced to suffer through slow code?

✅ IIS and Katana confusion

How does IIS relate to Katana if at all? I'm still confused by whether my app is using Katana or if IIS is just calling the dynamically registered Owin module package I have installed

How to pool SQLite connections

I am building a monolithic JSON api and wish to have sparate connection pools for readers and writers. System.Data.SQLite has connection option "Pooling" but there is no documentation what it does, and there is for example no MaxPoolSize or similiar. I am trying to achive 1 writer connection, and a pool of reader connections (1 connection per core max).

Question about Dependency Injection:

I’m currently using autofac for dependency injection in a project because I’m attempting to do a plugin architecture and it has some features for loading interfaces from dlls. I came across the Microsoft dependency injection library and learned that it can load from autofac containers with the extension. What’s the benefit of this over using autofac alone ?

Issues with ASP.NET Core Unobtrusive Validation on Dynamically Added Form Elements

Hello everyone, I'm having issues with unobtrusive validation in ASP.NET Core not working correctly on dynamically added form elements. I have a form with multiple input fields that can be dynamically added via JavaScript. I'm using jQuery and jQuery Unobtrusive Validation to handle client-side validation....

✅ Passing back to the main thread

Hiya I want to keep track of the amount of milliseconds that have passed in my game. So I've created a thread and told it to run this function. ` private void RunTimeUpdater()...

✅ Deep copy struct

There are a couple arrays sitting in Board and they get mutated by tempBoard.MakeMove()
No description

✅ Nested classes in C# with parent being a generic class

Hello guys, consider the code in the picture, can someone explain why the type parameters declared in our parent generic class is available in the nested private class please. Also notice in the following code: ```C# // Type parameter T in angle brackets....
No description

Enumerable.OrderBy help

I'm following a tutorial and they randomly get an element of an enumerable like this:
return unvisitedCells.OrderBy(_ => Random.Range(0, 10)).FirstOrDefault();
return unvisitedCells.OrderBy(_ => Random.Range(0, 10)).FirstOrDefault();
...

Publishing to microsoft store

I need help publishing to microsoft store. I tried to get it certified many times and keep getting a response about the tile icons. Can someone help me from step 1 to the last step?

Converting Legacy App to .Net 8

Hi, we've got a legacy app in .Net 4.6 Framework. it currently uses MSharp (which is not that known) framework, and I have been converting it to .Net 8 using clean-architecture as best as I can so far. One thing that bothers me is loading entity navigation data (with EF 8). ...

✅ Created a ASP.Net Core MVC project first time, build takes too long

I have created a project using default template, and when I click on Start Debugging button to run project with IIS Express and Firefox, the build creation remains in progress for more than 5 minutes. I have installed Visual Studio 2022 with .NET 8.

✅ Can't see code changes when app is running (vs code)

Hello, guys. Microsoft Learn website says that vs code has a way to see code changes to your app, while its running: Launching the app without debugging by selecting Ctrl+F5 allows you to: * Make code changes. * Save the file....

Duplicate objects in a DB Query

I'm querying entries from a table in a MySQL database with EFC. When I look at the table in Rider (or via cli for that matter) the table looks like the first image. However, if I start it in debugger mode and look at what the database query returns in my code, I get the first entry in multiple positions How is that even possible?...
No description