Anton
Anton
CC#
Created by Anton on 8/22/2024 in #help
Eagerly compile minimal apis
I want to initialize minimal apis on initialization rather than the first request. Is there a way to manually force it to initialize? Other than making a request to one of the endpoints from within the application.
12 replies
CC#
Created by Anton on 7/27/2024 in #help
Mapping metadata
Is there a mapping library that doesn't only do mapping, but can also map a PropertyInfo to the associated PropertyInfo in the other type? I wanted to propagate MaxLength from IModel of ef core to the dto's by backward mapping the entity back to the dto. I could do this by name only, but that obviously won't work the moment some name is different.
5 replies
CC#
Created by Anton on 7/25/2024 in #help
Process.Start print the command
I have an argument enumerable. There's a bunch of internal code that gets executed that produces the actual command that will be executed, but it doesn't seem to get saved anywhere. Is there a way to print the command that's going to be executed, besides copy-pasting the code that shell-escapes the argument enumerable and computing the command manually?
3 replies
CC#
Created by Anton on 7/15/2024 in #help
✅ How come this gives me no warning in Rider?
var f = File.Open("FDJLK", FileMode.Append);
var f = File.Open("FDJLK", FileMode.Append);
For context, I have this in MSBuild
<TreatWarningsAsErrors>true</TreatWarningsAsErrors>
<AnalysisLevel>preview</AnalysisLevel>
<TreatWarningsAsErrors>true</TreatWarningsAsErrors>
<AnalysisLevel>preview</AnalysisLevel>
And this in .editorconfig
dotnet_diagnostic.CA1001.severity = error
dotnet_diagnostic.CA1816.severity = error
dotnet_diagnostic.CA1001.severity = error
dotnet_diagnostic.CA1816.severity = error
What else do I have to do to make it work?
29 replies
CC#
Created by Anton on 7/10/2024 in #help
ASP.NET Core same structure for all responses
I need a package that could wrap any response I return from the controller into a standard structure. Kind of like this project https://github.com/proudmonkey/AutoWrapper The problem with that project is that it doesn't modify the responses that Swagger sees. I know I can take a shortcut by just returning the wrapped type from all endpoints, but that's just not plausible. I want it to work by default for everything. So things I need in particular: - Exception middleware that responds in json, with the same settings as configured for the response formatter. I don't really care about non-json, but ideally that should work too. - Handle model binding errors, responding in the same standard format. - The ability to handle custom exceptions, the ability for them to map to the model serialized. - I want it to distinguish 400 from 500 automatically. - The most important thing, I need it to affect swagger. The client should get the wrapped responses in swagger. If possible, the errors should be listed too. - Has to be non-invasive, in the sense that it has to be handled at a central place, rather than duplicated for each handler. I've tried doing some of this manually, but it's way more work than I anticipated.
1 replies
CC#
Created by Anton on 7/9/2024 in #help
Use the model binding configuration to map PropertyInfo to its input name in Json / query param
I don't want to duplicate any logic that aspnet core does itself. I want to get the name of the json property or a property from whatever other source that it would bind to the given property. This ideally should work for property paths, so nested models can be interpreted correctly.
1 replies
CC#
Created by Anton on 7/8/2024 in #help
MSBuild make it NOT copy a dependency to the output path
<!-- Make sure the CLI has been built before calling into it -->
<ItemGroup Condition="'$(IsTools)' != 'True'">
<ProjectReference Include="$(RootDirectory)tools\Cli\Cli.csproj">
<IncludeAssets>none</IncludeAssets>
<ExcludeAssets>all</ExcludeAssets>
<ReferenceOutputAssembly>false</ReferenceOutputAssembly>
</ProjectReference>
</ItemGroup>
<!-- Make sure the CLI has been built before calling into it -->
<ItemGroup Condition="'$(IsTools)' != 'True'">
<ProjectReference Include="$(RootDirectory)tools\Cli\Cli.csproj">
<IncludeAssets>none</IncludeAssets>
<ExcludeAssets>all</ExcludeAssets>
<ReferenceOutputAssembly>false</ReferenceOutputAssembly>
</ProjectReference>
</ItemGroup>
How in the world does this still end up copying everything but the dll? It copies the exe and runtimeconfig and deps jsons, whatever those are. I'm not going to be calling it at runtime.
16 replies
CC#
Created by Anton on 7/2/2024 in #help
VS Remove all bindings, then configure from scratch
Any real solution for this, besides clicking through their menus for each key individually? I found out by messing around that the base configuration gets imported from VSK files, available from the installation. But those are binary files. Any documentation on how to generate these? Or extract the bindings from them? Or a tool that does this? The format of the keymap config file is just xml, where you can define a <Shortcut> or do a <RemoveShortcut> to remove a default. So if I could read the vsk file, I could in theory <RemoveShortcut> all the things that are there.
4 replies
CC#
Created by Anton on 10/16/2023 in #help
❔ System.IO.Pipelines cannot complete the reader
No description
21 replies
CC#
Created by Anton on 6/23/2023 in #help
❔ Rider accepting completion deletes the next word
When I hit tab in Rider to accept a suggestion, it overwrites everything that comes after. Just like it does in this vid at the 15th second https://youtu.be/wCllU4YkxBk How do I disable that?
16 replies
CC#
Created by Anton on 3/31/2023 in #help
❔ Replacing joins to a table with a CTE in EF Core
Say I generate my sql with ef core. Is there a way to make it do joins on the CTE rather than the original table? So for example if I do a
context.Owners
.Select(o => new
{
Id = o.Id,
Projects = o.Projects,
});
context.Owners
.Select(o => new
{
Id = o.Id,
Projects = o.Projects,
});
Can I make the join with projects use a CTE, so it looks kinda like this:
context.Owners
.SubstituteJoins(context.Projects, p => p.Where(p => p.Name.Contains(" ")))
.Select(o => new
{
Id = o.Id,
Projects = o.Projects,
})
context.Owners
.SubstituteJoins(context.Projects, p => p.Where(p => p.Name.Contains(" ")))
.Select(o => new
{
Id = o.Id,
Projects = o.Projects,
})
Generating a query that's similar to this:
WITH view AS (
SELECT *
FROM projects
WHERE name LIKE '% %'
)
SELECT *
FROM owner
LEFT JOIN view ON view.ownerId = owner.id;
WITH view AS (
SELECT *
FROM projects
WHERE name LIKE '% %'
)
SELECT *
FROM owner
LEFT JOIN view ON view.ownerId = owner.id;
To be clear, what I want is for all joins with the projects table to be substituted for a join to a CTE. Since I think EF Core cannot generate CTE's, is there a way to just force it to replace joins with the Projects table to view, which I would then append to the SQL query as text? I guess an idea is to replace the strings which reference the Projects table after it generates the SQL, but is there a way to do this at one higher level of abstraction? Is my idea flawed, or is there a simpler way, you think? The same can kinda be achieved with nested queries on all nested fields, but my problem with this is that it requires redoing the projections. Thinking of the Projects table as a view feels simpler in this case.
3 replies
CC#
Created by Anton on 3/28/2023 in #help
❔ HotChocolate with IQueryable, apply a required filter on the ef entity
Basically, I'm trying to find a way to configure an IObjectFieldDescriptor by adding a required argument to it, which should in turn apply a filter on the database entity. In this case, I'm adding a companyId argument, and then applying the respective filter manually, before mapping. What should I do to configure this in a simpler way? Let me show you what I have and then what I mean by a better way. This is what I have so far. Don't mind the FieldCollectionQuery and UseBuiltinMiddleware extension methods, they are there to set up the ef core stuff. The argument is the important bit right now.
public sealed class QueryType : ObjectType
{
protected override void Configure(IObjectTypeDescriptor descriptor)
{
descriptor
.FieldCollectionQuery<SupplierGraphDtoType>("suppliers")
.Argument("companyId", a => a.Type<NonNullType<IntType>>())
.UseBuiltinMiddleware<SupplierGraphDtoType>(MiddlewareFlags.All)
.Resolve(ctx =>
{
var q = ctx.DbContext<DataContext>()
.Set<Supplier>()
.AsQueryable();

int companyId = ctx.ArgumentValue<int>("companyId");
q = q.Where(s => s.CompanyId == companyId);

return q.ProjectTo<Supplier, SupplierGraphDto>(ctx);
});
}
}
public sealed class QueryType : ObjectType
{
protected override void Configure(IObjectTypeDescriptor descriptor)
{
descriptor
.FieldCollectionQuery<SupplierGraphDtoType>("suppliers")
.Argument("companyId", a => a.Type<NonNullType<IntType>>())
.UseBuiltinMiddleware<SupplierGraphDtoType>(MiddlewareFlags.All)
.Resolve(ctx =>
{
var q = ctx.DbContext<DataContext>()
.Set<Supplier>()
.AsQueryable();

int companyId = ctx.ArgumentValue<int>("companyId");
q = q.Where(s => s.CompanyId == companyId);

return q.ProjectTo<Supplier, SupplierGraphDto>(ctx);
});
}
}
4 replies
CC#
Created by Anton on 3/24/2023 in #help
❔ Blazor WebAssembly CSS
2 replies
CC#
Created by Anton on 3/21/2023 in #help
❔ Using automapper to update EF Core entities recursively
I'm trying the neat idea to try and make a generic create/update method which supports includes. The first branch takes care of inserts. It takes requests of this form (currently doesn't check the nested ids, which it should):
{
"name": "John",
"projects": [
{
"projectName": "A"
},
{
"projectName": "B"
}
]
}
{
"name": "John",
"projects": [
{
"projectName": "A"
},
{
"projectName": "B"
}
]
}
It then maps this dto to a recursively tracked entity. The second branch works with requests of this form, taking care of updates:
{
"id": 1,
"projects": [
{
"id": 7,
"projectName": "Changed"
},
{
// Should not update anything, but try and find the project with this id.
"id": 8
},
{
"projectName": "Q"
}
]
}
{
"id": 1,
"projects": [
{
"id": 7,
"projectName": "Changed"
},
{
// Should not update anything, but try and find the project with this id.
"id": 8
},
{
"projectName": "Q"
}
]
}
Currently I'm doing a bunch of things that are related to nested entities manually. I'm manually sorting the projects in reverse order, so that the projects with null key (projects to be inserted), end up at the end of the list. I'm then querying the entity from the db, checking if all of the projects meant for updating were found, and then I do a recursive copy of the dto into that entity. This maps all properties of the person and of each nested project. At least it should, what actually happens is it copies the null values over as well (see the mapper profile below). Then the tracker picks up on all of the newly mapped projects. My question is, why does automapper map null properties even though it's set to ignore them, and is there a way to generalize this thing? The way I came up with doesn't seem overly complex, it's just not fully generic. I want the both the include filtering and the mappings to work independent of the level of depth of the objects.
21 replies
CC#
Created by Anton on 3/14/2023 in #help
❔ Preventing a panel from overflowing + show scrollbar WPF
I have a situation like this
<StackPanel>
<Grid>
some buttons
</Grid>
<StackPanel> possibly wrapped in ScrollViewer?
variable height content that may not fit
</StackPanel>
</StackPanel>
<StackPanel>
<Grid>
some buttons
</Grid>
<StackPanel> possibly wrapped in ScrollViewer?
variable height content that may not fit
</StackPanel>
</StackPanel>
The problem is that the bottom panel overflows on the y axis. Solutions online suggest setting it to the width of the container like here https://stackoverflow.com/questions/47333220/wpf-scrollviewer-content-overflowing which I obviously can't do. How do I hide the overflow? I want it to take all available space on the Y axis, but no more than the screen height.
11 replies
CC#
Created by Anton on 3/14/2023 in #help
❔ WPF a control to display an arbitrary object
It should support complex objects with multiple properties, int, string, and IEnumerable's of these. It's fine if it doesn't support nested collections. If the question is not clear, tell me to clarify it.
9 replies
CC#
Created by Anton on 2/23/2023 in #help
❔ WPF draw over other arbitrary controls
I want to draw over items contained in an ItemsControl, without wrapping the ItemsControl into any sort of other object. Can anyone suggest a starting point / best practice? With my knowledge of WPF I don't know where to start solving this one.
53 replies
CC#
Created by Anton on 2/18/2023 in #help
❔ Is something like this possible with the default DI package?
So what I want to do is like this How scopes work normally: - global scope - scope 1 * scoped service A * scoped service B - scope 2 * scoped service A (different instance) * scoped service B (different instance) What I want is to be able to resolve scoped services of the parent from a subscope, but create new services for some types in subscopes (are there even subscopes?) - global scope - scope 1 * service A - scope 1.1 * service A resolved to the one of the parent * service B - scope 1.2 * different instance of service B I've seen a lib allow this, but it's for Unity. They did it through custom scope classes. Autofac might allow this too? I'm not sure.
4 replies
CC#
Created by Anton on 2/17/2023 in #help
❔ Dotnet NuGet fetch packages with documentation
I can set <CopyLocalLockFileAssemblies>true</CopyLocalLockFileAssemblies> in the project file to enable copying the nuget packages on build. This makes the build in essence equivalent to publish. What I want, however, is for it to copy the xmls with the documentation instead, be it in publish or on build, I don't care. These xmls with documentation are located next to the dlls in the nuget packages. What property do I have to set to enable this?
5 replies
CC#
Created by Anton on 1/26/2023 in #help
❔ Multiple configurations with automapper
I have two automapper configurations, the first one is used to project entities to dtos when querying ef core normally or when just mapping objects, while the second one is for use with OData. A while back I have asked about conventions of service configuration, and the answer was quite different from my intuitive solution. So what I'm asking here is what's the conventional way of registering multiple automapper configurations? A factory by name or index does not seem to be officially supported by the public API, should I make a factory myself? Maybe some other library or option exists?
33 replies