|
EssOEss posted:My experience with Entity Framework is that it tends to get in trouble very fast once you start using fancy words like group by and join. I immediately ran into client-side evaluation or EF just giving up with some internal query builder exception when I last tried to use it for nontrivial cases. I only have positive experience using it as a simple row serializer/deserializer and suggest you expect no more from it. If EF can't translate that to nice SQL (which is very likely), the SQL is easy enough to write and can be parameterized: code:
Cold on a Cob fucked around with this message at 18:19 on Jun 21, 2021 |
# ? Jun 21, 2021 18:16 |
|
|
# ? Jun 8, 2024 08:07 |
|
I'm looking to upload a file to Amazon S3 in multiple parts using C# and either WebClient or HttpClient. The upload process is a 4-step operation: 1. Initiate a multipart upload 2. Create pre-signed URLs for each part 3. Upload the object’s parts 4. Complete multipart upload I've written methods for step 1, 2, and 4, but I'm not clear as to how to actually upload a file in parts. The parts need to be 5mb in size (or less for the final part), and I've created a method which calculates how many parts the chosen file should be split into. Here is a working example of uploading a file in a single part with a presigned URL: C# code:
In addition, whenever you upload a part, Amazon S3 returns an ETag header in its response. For each part upload, I need to record the part number and the ETag value.
|
# ? Jun 21, 2021 18:34 |
|
Supersonic posted:I'm looking to upload a file to Amazon S3 in multiple parts using C# and either WebClient or HttpClient. The upload process is a 4-step operation: Is there a reason you're not just using the utility class AWS provides for this?
|
# ? Jun 21, 2021 19:18 |
|
epswing posted:I believe Distinct for both Linq to Entities and Linq to Objects will not maintain ordering. For objects it should work: https://stackoverflow.com/questions/4734852/does-distinct-method-keep-original-ordering-of-sequence-intact It isn't documented it seems.
|
# ? Jun 21, 2021 19:44 |
|
New Yorp New Yorp posted:Although I'm not a huge fan of "throw another nuget package at it!" and I'm not sure if it works with IQueryable vs IEnumerable, MoreLINQ has a DistinctBy extension method that probably fits the bill here. yeah groupby should be what you want code:
hello elephant dusty banana apple .NET 6 finally adds DistinctBy so we won't even need to use another package soon! e: if you know its always ordered by id you could simplify it with something like code:
mistermojo fucked around with this message at 20:47 on Jun 21, 2021 |
# ? Jun 21, 2021 20:15 |
|
mistermojo posted:yeah groupby should be what you want IEnumerable and IQueryable are different things with different behaviors even though it looks like you’re just writing the same Linq syntax. This is one of the reasons I hate EF. Linq is very powerful but also has some footguns that devs run into when they don’t understand the difference between when a Linq query is describing functions performed on a sequence (IEnumerable) and when a Linq query is actually building an expression tree (IQueryable) that can be evaluated and executed on a sequence or any arbitrary data source that has a way to translate the expression tree into instructions it understands. EF just papers over this and says “Look at all the poo poo Linq can do! No need to worry about all that complicated poo poo like knowing what your databases are actually capable of or how you should structure your data for your chosen DB(s). Oop your app is eating up all your memory and/or CPU and/or what look like simple queries are taking way longer than expected to evaluate? You should have read the docs and known how all this poo poo works under the hood before deploying it!” The paradox of EF is that it demands you understand the various intricacies of Linq and how the data providers work internally in order to avoid firing one of the many footguns it hands to you, but once you understand what EF is doing for you and how it works internally, your best choice is usually “don’t use EF and write the queries/HTTP calls/etc myself”. ThePeavstenator fucked around with this message at 21:12 on Jun 21, 2021 |
# ? Jun 21, 2021 20:38 |
|
raminasi posted:Is there a reason you're not just using the utility class AWS provides for this? The software has a client and server component, and we don't want to put the AWS keys on the client (like the class requires). With a pre-signed URL supplied by the server, the client can initiate an upload without needing to have access to the AWS secret keys and gives us more flexibility for our needs.
|
# ? Jun 21, 2021 21:49 |
|
Re the EF question, just write some SQL (assuming you want the logic to happen on the db) rather than fighting with EF. Most SQL variants are really good at that sort of logic and it's easy to develop with interactive queries.
|
# ? Jun 22, 2021 14:30 |
|
pointsofdata posted:Re the EF question, just write some SQL (assuming you want the logic to happen on the db) rather than fighting with EF. Most SQL variants are really good at that sort of logic and it's easy to develop with interactive queries. Seconding this. I whipped this up in a few minutes in T-SQL: code:
code:
For reference, the interim ranking CTE looks like: code:
|
# ? Jun 22, 2021 16:03 |
|
You don’t need a cte for this, you can order by the max(Id) desc and grab the top 5 from that. Check the post I made earlier. This is easy as hell in sql.
|
# ? Jun 22, 2021 16:14 |
|
Oh yeah, guess you could to that too. I just like CTEs because they break stuff down into smaller units, and I use them quite often. E: poo poo yeah, way cleaner with the same result and shorter execution plan code:
NecroBob fucked around with this message at 18:33 on Jun 22, 2021 |
# ? Jun 22, 2021 18:29 |
|
NecroBob posted:
Blindly mimicking this with linq works C# code:
SQL code:
epswing fucked around with this message at 14:24 on Jun 23, 2021 |
# ? Jun 22, 2021 19:35 |
|
Edit: Ended up solving this.
Supersonic fucked around with this message at 16:40 on Jun 24, 2021 |
# ? Jun 24, 2021 16:24 |
|
Found a nasty bug in one of our WPF apps where things like checkboxes lose state when the user "switches user", the machine wakes from sleep etc. Found it can be eliminated by changing bindings from "OneWayToSource" to "TwoWay". Turns out when the window is recreated, it sets the state of the checkbox to the default unchecked state and that gets communicated to the data context. Trouble is, if we have a modal dialog showing and this changes the state of the viewmodel that spawned the modal dialog in a way we didn't anticipate (e.g. you wouldn't have been allowed to click the button that spawned the modal dialog, if the checkbox hadn't been clicked). At best it undoes the user's work, if they had decided to check the checkbox before locking their workstation and letting it sleep or w/e. This seems like a really obtuse behaviour. Why would you ever want "OneWayToSource" if it's going to gently caress you like this?
|
# ? Jun 28, 2021 13:10 |
|
I honestly can't think of a place I've ever needed to use OneWayToSource in a decade+ of WPF (mostly LOBs)
epswing fucked around with this message at 15:37 on Jun 28, 2021 |
# ? Jun 28, 2021 15:35 |
|
I don't think I've ever used OneWayToSource, but what an obnoxious edge case. Thanks for sharing! I feel like that's the kind of thing you'd Google forever and only find answers to if you got obscenely lucky.
|
# ? Jun 28, 2021 17:59 |
|
What is all y'all's experience with nullable reference types? Any great success stories to tell? I tried them out and just found it to be a nice idea that in practice is just a nuisance that did not help me at all. Wondering if this is a common experience or if there is a scenario where they prove worth bothering about.
|
# ? Jul 10, 2021 23:27 |
|
EssOEss posted:What is all y'all's experience with nullable reference types? Any great success stories to tell? I tried them out and just found it to be a nice idea that in practice is just a nuisance that did not help me at all. Wondering if this is a common experience or if there is a scenario where they prove worth bothering about. None actually, although I've been reading on how they want to implement it in F# and I am not excited. F# already has an option type to describe the absence of something but that wasn't good enough apparently. While I do like the pattern matching they did for C#; the language itself seems to be getting more and more top heavy. Instead of trying to keep things simple, they are going whole hog the other way with their development tools it seems. Trying to get websockets running on Kestrel you need to write your own middleware? Why? That seems like such base functionality. Something else; wanting to use audio or video on .Net is such a pain on something that is not Windows, I've decided to use Python. My god, the amount of libraries available to do almost anything is just wonderful. video4linux bindings? Here you go. Port audio? Sure. So now I use F# for the core logic, because it is just wonderful to use, and use Python for the devices. Websockets are used to get them talking to each other. It works pretty well. Mr Shiny Pants fucked around with this message at 08:32 on Jul 11, 2021 |
# ? Jul 11, 2021 08:29 |
|
EssOEss posted:What is all y'all's experience with nullable reference types? Any great success stories to tell? I tried them out and just found it to be a nice idea that in practice is just a nuisance that did not help me at all. Wondering if this is a common experience or if there is a scenario where they prove worth bothering about. It took me a couple of days to convert almost all of our API code to use NNRTs (don't know the LOC, but probably somewhere between 100,000 and 1,000,000, and closer to the bottom of that range), and in the process I was able to fix some actual/potential bugs and also remove a lot of superfluous null checks. Definitely not a nuisance. The only annoying thing I've encountered is when libraries I'm using don't support them yet, forcing me to temporarily disable them in a a few cases. This is the the case that comes to mind: C# code:
One other nuisance is that I've had occasional compiler/IDE bugs where the compiler is convinced that I need to either add a null check for some non-nullable value before using it, or that a null check for an actually nullable value is superfluous. I had that just the other day, and had to delete the bin/obj folders in the project to fix it. Other than that I have nothing but good things to say about it. The thing about it, though, is that making the plunge is similar to introducing async/await to code that didn't originally have it. It's a bit of an all or nothing, otherwise you don't get the benefits. So in a larger project I could see the risks/workload outweighing the benefits.
|
# ? Jul 11, 2021 10:14 |
|
LOOK I AM A TURTLE posted:The only annoying thing I've encountered is when libraries I'm using don't support them yet, forcing me to temporarily disable them in a a few cases. This is the the case that comes to mind: Are you sure about example above? When I try to implement interface from library that does not support NNRTs, I have no problem implementing the interface method with Foo? return type. On the other hand, if library does support NNRTs, then compiler rightfully complains and correct implementation would be to throw exception instead of returning null.
|
# ? Jul 12, 2021 10:10 |
|
LOOK I AM A TURTLE posted:The workaround is to either return null! I understand why this is necessary (if nothing else for the exact scenario you described) but lol that this is even allowed.
|
# ? Jul 12, 2021 10:24 |
|
Chrungka posted:Are you sure about example above? When I try to implement interface from library that does not support NNRTs, I have no problem implementing the interface method with Foo? return type. On the other hand, if library does support NNRTs, then compiler rightfully complains and correct implementation would be to throw exception instead of returning null. Hmm, you may be right. Perhaps the scenario I'm describing actually only applies to cases where the library has <Nullable>enable</Nullable>, but the particular interface hasn't been updated to correctly reflect the true nullability of the return value? I had this problem specifically with the IUserStore<T> interface in the Identity part of ASP.NET Core, where the FindById/Name/Email methods are defined as returning T rather than T?. I could implement the interface as IUserStore<User?>, but then it ends up being nullable in lots of other methods where it isn't desirable (UpdateUser etc.). NihilCredo posted:I understand why this is necessary (if nothing else for the exact scenario you described) but lol that this is even allowed. The first time I tried it I fully expected it to give some sort of "this expression is hosed" error, like when you do if (0 == 1), but nope.
|
# ? Jul 12, 2021 16:20 |
|
LOOK I AM A TURTLE posted:Hmm, you may be right. Perhaps the scenario I'm describing actually only applies to cases where the library has <Nullable>enable</Nullable>, but the particular interface hasn't been updated to correctly reflect the true nullability of the return value? I had this problem specifically with the IUserStore<T> interface in the Identity part of ASP.NET Core, where the FindById/Name/Email methods are defined as returning T rather than T?. I could implement the interface as IUserStore<User?>, but then it ends up being nullable in lots of other methods where it isn't desirable (UpdateUser etc.). LOOK I AM A TURTLE posted:The first time I tried it I fully expected it to give some sort of "this expression is hosed" error, like when you do if (0 == 1), but nope. This: https://www.youtube.com/watch?v=V9qTsDg-RPo
|
# ? Jul 12, 2021 19:21 |
|
EssOEss posted:What is all y'all's experience with nullable reference types? Any great success stories to tell? I tried them out and just found it to be a nice idea that in practice is just a nuisance that did not help me at all. Wondering if this is a common experience or if there is a scenario where they prove worth bothering about. At best/most I'll use code:
code:
|
# ? Jul 12, 2021 20:04 |
|
Chrungka posted:I think you should go with IUserStore<User?>. Having to implement Task<IdentityResult> UpdateAsync(User? user, CancellationToken cancellationToken) with regular null check via ArgumentNullException might be inconvenient. But returning null when contract explicitly says it doesn't return null is IMHO a bug in code. No, the FindByX methods are definitely intended to return null if the user isn't found. That's what the default implementation for EF Core does, for example: https://github.com/dotnet/aspnetcore/blob/69eb4b38bca90bb830f290a6eaa5a61650dc87ac/src/Identity/EntityFrameworkCore/src/UserStore.cs#L234 (you have to dig through the references a bit to see that it returns null, but trust me, it does). Either they just haven't changed the definition to TUser? yet, or there's some reason (like backward compat) that prevents them from changing it. Edit: To clarify, I agree that it's reasonable enough to implement it as TUser?, but seeing as how the default FindByX methods return null, while all the other methods explicitly throw if the input is null, it seems clear to me that the ideal interface would mark the Find methods with a question mark, but not the others. LOOK I AM A TURTLE fucked around with this message at 21:46 on Jul 12, 2021 |
# ? Jul 12, 2021 20:37 |
|
Has anyone used Npgsql? Connected by specifying a DbProviderFactory in app.config? I'm trying to get this to work, but when I run the app it always throws "The connection string for the database 'database_name' does not exist or does not have a valid provider. ---> The requested database database_name does not have a valid ADO.NET provider name set in the connection string. (C:\...\connectionStrings.config line 3)" These lines are taken from app.config: code:
code:
code:
code:
|
# ? Jul 29, 2021 20:36 |
|
Speaking of nullables, is it possible to enable them in a shared project (shproj)? I've been doing "#nullable enable" in every file, but that's kind of annoying for an on-going project.
|
# ? Jul 30, 2021 04:21 |
|
Hammerite posted:snip Not trough app.config. This is what I've used inside code: code:
|
# ? Jul 30, 2021 07:32 |
|
I've got it working now. The problem was something much dumber - I was putting that db provider stuff in the app.config of the library that communicates with the db, and it needed to be in the app.config of the C++ app that uses the library. Now I'm on to the next problem.
|
# ? Jul 30, 2021 10:04 |
|
Hammerite posted:I've got it working now. The problem was something much dumber - I was putting that db provider stuff in the app.config of the library that communicates with the db, and it needed to be in the app.config of the C++ app that uses the library. Now I'm on to the next problem. Good luck Glad you got it working. I always found working with Npgsql pretty nice.
|
# ? Jul 30, 2021 13:33 |
|
Anyone working with ArrayPools? I am doing some work which uses quite a lot of arrays (framebuffers) and I was just wondering if the speedup is worthwhile. I also use arrays for websockets, would these also be a good candidate? I have quite a lot of 64K arrays coming in. I am mostly looking for anyone who has some experience using them. Another question: how would I profile this?
|
# ? Aug 2, 2021 18:19 |
|
I'm going to ask this here too because it doesn't look likely that Stack Overflow is going to be much help. How do I get C# to print out the exact value represented by a floating-point number in memory? I'm looking to create a function f such that this code: code:
... which is, if I got my maths right, the actual value represented by the bit pattern of the float. myFloat.ToString("F50") is no help. It just prints out 0.10000...000, which is
|
# ? Aug 28, 2021 18:15 |
|
Hammerite posted:I'm going to ask this here too because it doesn't look likely that Stack Overflow is going to be much help.
|
# ? Aug 28, 2021 18:41 |
|
mystes posted:Try G50 instead. G50 gets you 0.100000001 the Microsoft docs specify that using G with enough decimal places will give you a representation that should round-trip correctly (which I assume is borne out here; I've not tested it). It doesn't say you will get the value actually represented in memory.
|
# ? Aug 28, 2021 19:22 |
|
It gives the number you wanted in your example at least, on .NET 5. You only need G9 to round-trip a float, so it seems to be formatting as much as it can. Maybe.
|
# ? Aug 28, 2021 20:10 |
|
drat, it does the right thing on net core 3.1 as well. Just Framework where it doesn't. Unfortunately the place where I wanted to do this is a framework app. Well, I will just have to do without.
|
# ? Aug 28, 2021 20:19 |
|
Hammerite posted:drat, it does the right thing on net core 3.1 as well. Just Framework where it doesn't. Unfortunately the place where I wanted to do this is a framework app. Well, I will just have to do without. Create a .dll in netCore or .NET 5 that does what you want and reference it? I’ve managed to make things work that way when there was no way to switch to a higher framework that supported TLS2.1
|
# ? Aug 28, 2021 21:05 |
|
https://devblogs.microsoft.com/dotnet/preview-features-in-net-6-generic-math/ We're getting THIS close to having typeclasses in .NET
|
# ? Sep 1, 2021 09:49 |
|
Someone on Reddit a couple months ago claimed that they didn't want to try to add typeclasses to f# because there was a distinct possibility they were actually going to get added to .net in general.
|
# ? Sep 1, 2021 11:36 |
|
|
# ? Jun 8, 2024 08:07 |
|
I don't understand the theory, but my question is: would typeclasses give us discriminated unions in c#?
|
# ? Sep 1, 2021 12:01 |