by

Where communities thrive


  • Join over 1.5M+ people
  • Join over 100K+ communities
  • Free without limits
  • Create your own community
People
Repo info
Activity
    Skeferstat
    @Skeferstat
    So, my question is, can I inject the db context the same way into a class library?
    Joe4evr
    @Joe4evr
    not directly, because your DbContext is defined above the library, and in project layering you can only utilize types that are defined below it
    that's the reason you create a repository interface at that project level, with its implementation higher up so the DbContext can get injected there and the interface providing the ability to be passed to services lower down
    Michał Zegan
    @webczat
    ef framework core question, playing randomly with queries and npgsql, observing what it generates. is it possible to make it to generate subqueries?
    Michał Zegan
    @webczat
    got it actually :P
    blizzardsolution
    @blizzardsolution
    hello, could anyone help me with connecting azure postgresql in asp.net core 3.1?
    Using this connection string: Server={host}.postgres.database.azure.com;Database={your_database};Port=5432;User Id={user_id};Password={your_password};Ssl Mode=Require;, i tried to publish the web api to azure services, but got a deploy error
    Alberto Passalacqua
    @AlbertoPa
    @blizzardsolution this should help: https://www.dotnetcurry.com/aspnet/1410/aspnet-core-app-postgresql-azure
    Once you have the connection string, install the npgsql plugin for EF Core, set the connection string and use something like this in your Startup.cs in place of the instructions for SQLServer:
    services.AddDbContext<ApplicationDbContext>(options =>
                    options.UseNpgsql(
                        Configuration.GetConnectionString(
                            "DefaultConnection"));
    blizzardsolution
    @blizzardsolution
    @AlbertoPa , thanks for replying!! i installed npgsql package and used the same code in Startup.cs
    trying to deploy the api to azure, i got the dploy error:
    C:\Program Files\dotnet\sdk\3.1.202\Sdks\Microsoft.NET.Sdk.Publish\targets\PublishTargets\Microsoft.NET.Sdk.Publish.MSDeploy.targets(140,5): Error : Web deployment task failed. (The value 'Server={host}.postgres.database.azure.com;Database={your_database};Port=5432;User Id={user_id};Password={your_password};Ssl Mode=Require;' is not a valid connection string or an absolute path.  Learn more at: http://go.microsoft.com/fwlink/?LinkId=221672#ERROR_INVALID_CONNECTION_STRING.)
    
    The value 'Server={host}.postgres.database.azure.com;Database={your_database};Port=5432;User Id={user_id};Password={your_password};Ssl Mode=Require;' is not a valid connection string or an absolute path.  Learn more at: http://go.microsoft.com/fwlink/?LinkId=221672#ERROR_INVALID_CONNECTION_STRING.
    Keyword not supported: 'port'.
       at System.Data.SqlClient.SqlConnectionStringBuilder.GetIndex(String keyword)
       at System.Data.SqlClient.SqlConnectionStringBuilder.set_Item(String keyword, Object value)
       at System.Data.Common.DbConnectionStringBuilder.set_ConnectionString(String value)
       at System.Data.SqlClient.SqlConnectionStringBuilder..ctor(String connectionString)
       at Microsoft.Web.Deployment.ConnectionStringMatcher.RemoveExtraSlashFromDataSourceName(String connectionString)
       at Microsoft.Web.Deployment.ConnectionStringMatcher.GetStandardConnectionString(String userConnectionString, Boolean isSqlCE)
       at Microsoft.Web.Deployment.SqlInfo.GetBuilder(String connectionString, String errorMessageFormat)
    Publish failed to deploy.
    
    2>Build failed. Check the Output window for more details.
    Alberto Passalacqua
    @AlbertoPa
    uhm interesting... what do they give in their screen for the connection string? Maybe they dropped the Port option and force one? :-?
    blizzardsolution
    @blizzardsolution
    Actually, port 5432 is included in the connection string
    Alberto Passalacqua
    @AlbertoPa
    that error seems odd indeed
    have you tried asking in https://gitter.im/npgsql/npgsql ?
    blizzardsolution
    @blizzardsolution
    image.png
    this is my web deploy setting
    nope, not tried asking there
    Alberto Passalacqua
    @AlbertoPa
    probably a minor detail that is hard to spot... as usual :-(
    blizzardsolution
    @blizzardsolution
    i see :( ... where should I ask about this?
    Alberto Passalacqua
    @AlbertoPa
    if you have an Azure subscription, I'd bug them ;-)
    they seem responsive on Twitter in my limited experience
    blizzardsolution
    @blizzardsolution
    okay, got you. thank you
    Alberto Passalacqua
    @AlbertoPa
    the gitter channel I posted above may also help... doesn't hurt to try
    SIkebe
    @SIkebe
    Is there anyone who are using ASP.NET Core Identity with Oracle? It has been 8 months since .NET Core 3.0 released, but ODP.NET for EF Core 3.0 or later has not been released yet. (There isn't even a beta version...)
    oracle/dotnet-db-samples#49
    Joe4evr
    @Joe4evr
    tbh, that's an Oracle problem
    SIkebe
    @SIkebe
    Yeah, definitely :confused:
    alealpha2000
    @alealpha2000
    hi! i am looking for some advice. i am writing an app that needs to retry post requests. how do I ensure the server detects a post retry and returns a cached response when a retry is detected? is there any "official" way to do that?
    duckblaster
    @duckblaster
    general method is to add a request id to the original request, retries use the same request id, backend ignores it if it has seen that id before
    alealpha2000
    @alealpha2000
    yup that's exactly what i did. only instead of ignoring it a cached response is sent on a retry
    duckblaster
    @duckblaster
    well, it doesn't do the requested work, so that counts as ignoring in my book :P
    Jesper Hansen
    @jespersh
    If dotnet ef database update outputs More than one DbContext was found, is there a parameter I can set so it tells me what it found?
    Michał Zegan
    @webczat
    yes
    Jesper Hansen
    @jespersh
    oh -v
    Finding DbContext classes in the project...
    Found DbContext 'ApplicationDbContext'.
    Found DbContext 'PersistedGrantDbContext'.
    Found DbContext 'ConfigurationDbContext'.
    Michał Zegan
    @webczat
    dotnet ef dbcontext list? not sure how it was exactly, but in any case the general answer is yes, there is a command to list db contexts.
    oh, or -v, yes
    Jesper Hansen
    @jespersh
    @webczat yours is better though. Gives the full namespace
    Jesper Hansen
    @jespersh
    Thanks. Still learning these commands. Ended up with running this inside the Blazing.Storage project folder: dotnet ef --startup-project ..\BlazingServer\ database update --context PersistedGrantDbContext. In case anyone would need this knowledge in the future
    Sanjeev M
    @zeus82
    I'm trying to host and SPA along side some razor pages... I want my SPA to be at '/app'. but I can't for the life of me figure out how to do that... this does not work, but its the thing that makes the most sense to me...
    app.UseSpa(spa =>
                {
                    spa.Options.SourcePath = "ClientApp";
                    spa.Options.DefaultPage = "/app/";
    
                    if (env.IsDevelopment())
                    {
                        spa.UseReactDevelopmentServer(npmScript: "start");
                    }
                });
    Panos Athanasiou
    @panoukos41
    When i call add on my entity i get the message "Argument types do not match" but i know my types is the same with the DbSet and its the same one in my database. This is my code for this class, it has a custom ValueComparer i suspect something must be wrong there is this correct ? and if no how do i do it the correct way ? This happens when i call the add method to add a new object to the database.
            private readonly ValueComparer<ICollection<string>> valueComparer = new ValueComparer<ICollection<string>>(
                equalsExpression: (c1, c2) => c1 != null && c2 != null && c1.SequenceEqual(c2),
                hashCodeExpression: c => c.Aggregate(0, (a, v) => HashCode.Combine(a, v.GetHashCode())),
                snapshotExpression: c => c.ToHashSet());
    
            public void Configure(EntityTypeBuilder<User> builder)
            {
                builder.Property(x => x.FavoriteStores)
                    .HasConversion(
                        to => string.Join(',', to),
                        from => from.Split(',', StringSplitOptions.None))
                    .Metadata
                        .SetValueComparer(valueComparer);
            }
        }
    Ofc you spend hours searching and then you find the answer right after you ask.... remove the ToHashSet in the snapshotExpression fixed it: https://github.com/dotnet/efcore/issues/17471#issuecomment-579125422
    DmitryChekh
    @DmitryChekh
    Why my JWT token is invalid?
    I can't request method which required authorization.
    I check on jwt.io and there my token is "Invalid signature"
    https://pastebin.com/SUUK7Wgn
    L Suarez
    @lsuarez5280
    Invalid signature only shows up there if you don't input the signature keys. It doesn't mean the token's actually invalid.
    Generally diagnostic tools will show any reasons policy failed in the traces.
    A tangential question about Visual Studio. Does anyone know if you can roll back to 16.5.x? The latest 16.6.0 is causing failures in our dacpac deploys.
    TeBeCo
    @tebeco
    can invalid signature happen if you use data protection but forgot to mutualize the key store ;)
    or you tempered the token ^^
    Jesper Hansen
    @jespersh

    What am I doing wrong here Microsoft.AspNetCore.SignalR.HubException: Failed to invoke 'GetCategory' due to an error on the server.? In my blazor's signalr client:

            public Task<CategoryModel> GetCategory(int id)
            {
                var cancellationTokenSource = new CancellationTokenSource();
                return _hubConnection.InvokeAsync<CategoryModel>("GetCategory", id, cancellationTokenSource.Token);
            }

    simplified in my aspnetcore signalr hub/server:

            public async Task<CategoryModel> GetCategory(int id, CancellationToken cancellationToken)
            {
                return new CategoryModel((uint)id); // real version has dbcontext and such
            }

    I have working cases with StreamAsync and SendAsync, but InvokeAsync has me scratching my head

    Jesper Hansen
    @jespersh
    It seems to be related to the CancellationToken. If I remove , cancellationTokenSource.Token and , CancellationToken cancellationToken then it gets called. What's the correct use for the token here?
    Jesper Hansen
    @jespersh
    Context.ConnectionAborted inside the hub is the answer?
    pm64
    @pm64
    Did anyone attend Build this year and receive a "Microsoft employee store discound from Microsoft Build" email? I can't tell if this is spam/fraud or not.
    The email comes from the domain "microsoft.regsvc.com" and links to a web site under the domain "store.ecompanystore.com"