by

Where communities thrive


  • Join over 1.5M+ people
  • Join over 100K+ communities
  • Free without limits
  • Create your own community
People
Repo info
Activity
    this is how generic registration works for example (your enum here)
    here is the registration per type (the name here would be your enum)
    if you want the equivalent of TypedHttpClient
    This message was deleted
    I mean, the things you're trying to do has already been implemented so you can take a look at existing code
    Psilon
    @Pzixel

    because you don't want ? or limitation

    Because I consider it as a code smell

    We have a type that maps something to something else called Dictionary
    and I don't want to care about how these things are created
    and if your business code depends on Microsoft.Extensibility.Abstractions then maybe something went wrong
    IMO
    Anthony Iacono
    @AnthonyIacono12_twitter
    Hello! I posted a question in the ASP.NET Core Github, but it was closed and they recommended I try asking here. Does anyone have any guidance on the following: dotnet/AspNetCore.Docs#18410
    Skeferstat
    @Skeferstat

    Hi, I have created a web api (asp.net core 3) with ef core.
    In my controller I have a method like this:

        public Task<List<Address>> Get() {...}

    If I use a DbContext like this (in my StartUp.cs):

    services.AddDbContext<BimConnectContext>(options =>
                    options.UseSqlServer(Configuration.GetSection("Database:ConnectionString").Value;  
                );

    I get the correct data back. All properties have the correct value ("Street": "Main Street 6").

    If I add UseLazyLoadingProxies( ) to the dbcontext options the properties in my answer object doesn't have the correct value. So I get for "Street": "string".

    I see this via swagger.

    The second problem, is If I use a http client for acces this api:

    • without UseLazyLoadingProxies() the http client returns the correct data
    • with UseLazyLoadingProxies() the http client NEVER returns...

    What I am doing wrong? Thanks in advance!

    Anthony Iacono
    @AnthonyIacono12_twitter
    @Skeferstat does anything change if you add:
    services.AddEntityFrameworkProxies();
    after your call to AddDbContext?
    Skeferstat
    @Skeferstat
    No, nothing
    Maybe, this is an await problem?...
    I see, if proxies are active, that the return type changes to proxy classes. In my debugger I see all data correct. All properties are filled with right values. But in swagger this properties with values like "string".
    Skeferstat
    @Skeferstat
    So dbcontext returns all data correctly.
    Skeferstat
    @Skeferstat
    What is the right way to get data async from database within a repository pattern, include this repository in a controller and then access this api with a htpp client? Where is await needed and in the right place?
    Anthony Iacono
    @AnthonyIacono12_twitter
    Do you mind sharing your implementation of Get()?
    Skeferstat
    @Skeferstat

    No problems, here is nothing special...
    Repository

    public Task<List<Address>> Get()
    {
    return _context.Adresses.ToListAsync();
    }

    Controller:

    public async Task<List<Address>> Get()
    {
    return await _repository.Get();
    }

    Anthony Iacono
    @AnthonyIacono12_twitter
    So it looks pretty standard, nothing crazy here. Here's a better question: What do you hope to accomplish by adding UseLazyLoadingProxies?
    Skeferstat
    @Skeferstat
    Get the navigation properties automatically
    And the InverseProperty
    Anthony Iacono
    @AnthonyIacono12_twitter

    So you don't want to have to do like:
    _context.Addresses.Include(a => a.User).ToListAsync()

    for example?

    Skeferstat
    @Skeferstat
    I have a class Adress and an adress has a "parent" address. So I need all the sub-addresses of an adress, and the for each sub-address hers sub-adresses and so on...
    So _context.Addresses.Include(a => a.InversePropertyForAddress) returns only the sub-adresses for the first level...
    so if adress1 has 5 sub-adresses and I call GetById(string addressId) then I get all 5 subadresses. But foreach sub-address the InversePropertyForAddres is empty. But I know, that der second sub-Address has two sub-addresses to...
    Anthony Iacono
    @AnthonyIacono12_twitter
    Ooh okay. So you want all the addresses, those addresses's parent addresses, and over and over until there are no more parents to the parents
    That's very interesting, I've never had to do that with EF core. But honestly I don't think that is what UseLazyLoadingProxies is for
    Navigation properties are lazy loaded by default (every time that I've ever used them)
    Skeferstat
    @Skeferstat
    Is there any another way how I can access this data?
    Skeferstat
    @Skeferstat
    okay, I think, I have more logical problem.. ;) I will rewrite my logic ;)
    Skeferstat
    @Skeferstat
    Hi, I have a asp.net core application and a .net standard library. Both should use the same dbcontext. How I can inject the dbcontext to the .net standard library? Thansk in advance!
    Joe4evr
    @Joe4evr
    @Skeferstat this is a good opportunity for you to learn about layering and loose coupling
    an easy thing to do would be to move your DbContext down to a new library that both other projects depend on, but you may already see why that would be impractical, especially since you're likely to have tweaked the DbContext to specifically suit the app
    Joe4evr
    @Joe4evr
    the more general approach is to define an interface - maybe in the library you mentioned, maybe in a new library that both will depend on
    and this interface will define the set of operations you need, like your basic CRUD functions and other things: this is your I{Thing}Repository
    in your lib, you accept an instance of the repository as a dependency in places where you need it
    and in your app, you create a class that implements that repository interface that accepts the DbContext as a dependency
    Skeferstat
    @Skeferstat
    Okay, but one more question. I'm asp.net core I can inject dbcontext into a repository, like MyRepository(DBContext context). So, ms yu
    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"));