Where communities thrive


  • Join over 1.5M+ people
  • Join over 100K+ communities
  • Free without limits
  • Create your own community
People
Activity
    Bart Koelman
    @bart-degreed
    Announcement: we'd like to implement end-to-end optimistic concurrency in JADNC. Our design considerations are described at json-api-dotnet/JsonApiDotNetCore#1004 and we're looking for feedback. Would this meet your needs and expectations? Please let us know in the linked issue. Thanks!
    Björn Harrtell
    @bjornharrtell
    Interesting. I've not yet had the pleasure of having to deal with this situation. I do have system which has the requirement but in that system it's solved by essentially branching and merging with manual conflict resolution if needed. In other cases I've wondered if fx. PostgreSQL serializable isolation is the way to go... but I suppose this is a more general non RDBMS specific solution? (and perhaps I don't understand serializable isolation well enough)
    Bart Koelman
    @bart-degreed
    Postgres serializable (similar to MSSQL snapshot) isolation level act as if taking a snapshot of the database, taking locks as data is being modified. This process takes place in milliseconds while handling a single request. Our proposal can span several hours between getting the data, displaying it and updating it.
    Björn Harrtell
    @bjornharrtell
    So it's not about concurrent request but rather long term transactions involving multiple requests? Not sure I see when I would want to use a generic solution for that... I have a concern then is that this feature might leak complexity into the code and use of JADNC in general when not using the feature.
    Bart Koelman
    @bart-degreed
    It is unrelated to transactions, I only mentioned them because you asked about it. The proposal is about preventing clients to overwrite each others changes, similar to merge conflicts in git. Please read the proposal and the links for details and ask your questions there.
    Bart Koelman
    @bart-degreed
    Announcement: We've published a beta for v4.2 because we'd like to get feedback on the new extensibility points for handling custom business logic. Please give it a try and let us know if it doesn't fit your needs. We don't want to make breaking changes after we release the final version.
    fauna-brecht
    @fauna-brecht
    Hi everyone, I love the framework and how well it's documented, it helped us a lot.
    While testing though I noticed that my links in the -> many direction don't work and always return an empty dataset. For example:
    Does anyone know what the problem would be in such a situation? I defined the relation in both directions in my IIdentifiable
    fauna-brecht
    @fauna-brecht

    In Device:

            [HasMany]
            public virtual ICollection<Datapoint> Datapoints { get; } = new List<Datapoint>();

    and Datapoint:

            [HasOne]
            public virtual Device Device { get; set; }
    Bart Koelman
    @bart-degreed
    Hi @fauna-brecht, thanks for reaching out. Does it help to add a setter to the collection property and remove the list assignment? If not, please create an issue so we can investigate.
    fauna-brecht
    @fauna-brecht
    It does, I was following stylecop advice, else I wouldn't have done it. Thank a lot for your help @bart-degreed
    RKennedy9064
    @RKennedy9064
    Does anyone know if there's an easy way to manually serialize/deserialize a jsonapi response using the current library? Usually I use EmberJS, which handles all the binding automatically. I'm playing around with Blazor now and was wondering if it's possible to just use JsonApiDotnetCore to serialize/deserialize my models in C# on the front end to send back to the server. Anyone have any experience doing something like that, or know if it's currently possible?
    Bart Koelman
    @bart-degreed
    @RKennedy9064 I've never tried that, but there's a list of client libraries at https://jsonapi.org/implementations/#client-libraries-net, which may help. In the future, we'd like to add OpenAPI support for JADNC, although we don't expect to have that available anytime soon. In the meantime, there's also https://github.com/json-api-dotnet/JsonApiDotNetCore/tree/master/src/JsonApiDotNetCore/Serialization/Client/Internal, though I should note it is not thoroughly tested and I cannot guarantee we'll keep offering that. To use that, you'll need to build a resource graph first, see https://github.com/json-api-dotnet/JsonApiDotNetCore/tree/master/test/JsonApiDotNetCoreExampleTests/IntegrationTests/ResourceHooks for an example.
    RKennedy9064
    @RKennedy9064
    @bart-degreed Sounds good, I'll look into the resource graph and internal serialization to see if that's viable. I looked at a few of the client libraries and there seems to be a few light weight ones, just hoping to limit my dependencies and not add another json api library just to serialize/deserialize on the client end.
    Wayne Douglas
    @wayne-o
    Hi - I'm trying out the operations stuff and am having some success getting it working - so that's awesome - it's seemingly very slow however - would you expect adding 2 records and updating one to link to the other to take around 30 seconds?
    Wayne Douglas
    @wayne-o
    here is my payload: https://gist.github.com/wayne-o/2aa2dfb98860f8fa8226c646e27e0975 - the draft-order already exists - hense it is not created in this operations array
    Wayne Douglas
    @wayne-o
    it seems to be spending an inordinate amount of time on "Attempting to validate the bound parameter "
    3 replies
    Wayne Douglas
    @wayne-o
    The model its validating btw is the operations model
    Wayne Douglas
    @wayne-o
    Also it takes a LOT longer when deployed - as in minutes not seconds
    dickalexei
    @dickalexei

    Hi,

    Seems that there is no native way to manage additional fields in join table in EF Core 6. Then we still need to define it manually as explained here.

    We still need to use HasManyThroughAttribute to declare the join table, but my problem is to retrieve the additional field from the defined relation...

    Do you have any advice how to do that? Or need to create an issue?

    Maurits Moeys
    @maurei
    In this case the approach would be to model your join table as a resource
    dickalexei
    @dickalexei
    That's the way i've done it, but wanted to ask if there is any more appropriate way.
    Bart Koelman
    @bart-degreed
    EF Core 5+ does support additional properties on many-to-many relationships, see https://www.youtube.com/watch?v=W1sxepfIMRM&t=2770s and https://docs.microsoft.com/en-us/ef/core/modeling/relationships#join-entity-type-configuration. However, there is no way to expose such properties in json:api, because relationships cannot have attributes. If you need that, you'll need to model the join table as a resource instead.
    dickalexei
    @dickalexei
    Thank you !
    taccommandeur
    @taccommandeur
    Hi everyone, I have a question about an error I am getting when trying to include a resource.
    taccommandeur
    @taccommandeur

    When doing a post on an endpoint I get the following error:

    POST: https://localhost:5001/api/v1/students?include=processes

    Response body:

    {
        "errors": [
            {
                "id": "081e90ef-9659-48bd-a08b-f5ea8d9c9a1c",
                "status": "500",
                "title": "An unhandled error occurred while processing this request.",
                "detail": "The LINQ expression 'OUTER APPLY Projection Mapping:\n(\n    SELECT t.Id, t.StudentId, s0.Id AS Id0, s0.Email\n    FROM Projection Mapping:\n    (\n        SELECT TOP(@__Create_Item1_0) p.Id, p.StudentId\n        FROM Processes AS p\n        WHERE t.Id == p.StudentId\n        ORDER BY p.Id ASC\n    ) AS t0\n    INNER JOIN Students AS s0 ON t.StudentId == s0.Id\n) AS t1' could not be translated. Either rewrite the query in a form that can be translated, or switch to client evaluation explicitly by inserting a call to 'AsEnumerable', 'AsAsyncEnumerable', 'ToList', or 'ToListAsync'. See https://go.microsoft.com/fwlink/?linkid=2101038 for more information."
            }
        ]
    }

    I am trying to debug the error but I am fairly new to .NET. I am guessing I must have something misconfigured somewhere in either the db context or my resource class. But my main problem now is that I don't understand what the error means. Does anyone have any pointers to where I should start looking to fix this?

    taccommandeur
    @taccommandeur

    The weird thing is that in my request body (when I dont do ?include=processes) I am getting relationship links for my resource:

    https://localhost:5001/resource-api/v1/processes/08d930ca-5e91-45c7-8c8f-e4f06ac1a009/student <- this endpoint works
    https://localhost:5001/resource-api/v1/students/08d930bf-1e73-40ba-80da-ab3b24e5298e/relationships/processes <- this link does not work

    To me it looks like the foreign id is found, but the entity is not hydrated.

    taccommandeur
    @taccommandeur
    The response body of POST: https://localhost:5001/api/v1/students?include=processes when I don't [EagerLoad] the related entity is actually:
    {
        "errors": [
            {
                "id": "dd63ec2e-34b4-4af7-bd77-8ee3a4824dd2",
                "status": "500",
                "title": "An unhandled error occurred while processing this request.",
                "detail": "The LINQ expression 'ROW_NUMBER() OVER(PARTITION BY p.StudentId ORDER BY p.Id ASC)' could not be translated. Either rewrite the query in a form that can be translated, or switch to client evaluation explicitly by inserting a call to 'AsEnumerable', 'AsAsyncEnumerable', 'ToList', or 'ToListAsync'. See https://go.microsoft.com/fwlink/?linkid=2101038 for more information."
            }
        ]
    }
    Bart Koelman
    @bart-degreed
    @taccommandeur Can you open an issue for this and fill out the fields? That helps us to narrow it down.
    taccommandeur
    @taccommandeur
    I can make an issue for this, but I am probably just doing something wrong so it is most likely not an issue with the package.
    taccommandeur
    @taccommandeur
    I found out that an issue exists json-api-dotnet/JsonApiDotNetCore#922
    taccommandeur
    @taccommandeur
    And it has a workaround that fixed the issue for me :)
    This package is really great so far.
    Bart Koelman
    @bart-degreed
    Thanks
    Björn Harrtell
    @bjornharrtell
    Unless I'm mistaken publicName for a resource is pluralized by default (not sure if that was changed at some point) and since 4.0.0 stable release it does not accept anything else in payloads. In 4.0.0-beta1 it seems it accepted singular name (or possibly didn't even validate at all if it was deducable from relationship).
    1 reply
    Björn Harrtell
    @bjornharrtell
    I'll see if I can get to create a good reproduction. I'm undecided if there is something to actually fix though.
    Bart Koelman
    @bart-degreed
    You've got another release ready for use: JsonApiDotNetCore v4.2! See the release notes at https://github.com/json-api-dotnet/JsonApiDotNetCore/releases/tag/v4.2.0 and https://github.com/json-api-dotnet/JsonApiDotNetCore.MongoDb/releases/tag/v4.2.0-alpha1 for what's new.
    Bart Koelman
    @bart-degreed
    We need some help! Does anyone know Ember.js? Although I'd never used Ember.js before, I was able to update https://github.com/json-api-dotnet/TodoListExample to the latest version. It works, but it produces many linter errors due to old JavaScript syntax. And it has various security vulnerabilities for old depencencies. So it would be great if someone can give it some love and update it to modern standards, possibly add some styling too. PRs welcome!
    Björn Harrtell
    @bjornharrtell
    I'm quite fluent in Ember. I'll check it out. 🙂
    2 replies
    Pranav Singh
    @pranavq212
    I want only to use GET methods & disable all other methods for PUT, DELETE OR POST in all controllers. Is there some configuration that allows this?
    2 replies
    In Other words I want only read-only JSON API, is there any out-of-box way to do this ?
    jrlmasangkay
    @jrlmasangkay

    Hi All, I have an issue with binding a PATCH request body to my model.

    I've done the follow steps as per the docs:

    1. Added all my tables to the DbContext
    2. Called "discovery.AddCurrentAssembly" in ConfigureServes

    But it's still coming up as null when I try to hit the API.
    I'm using EntityFramework btw.

    Would anyone know why the binding is not registering?

    2 replies
    jrlmasangkay
    @jrlmasangkay
    Hi All, another question. Any ideas on what could cause slow data binding for atomic operations? It takes me 40 seconds to bind a request body containing only 1 add request. I can log an issue if required but I just wanted to know first if anyone else has encountered this issue?
    8 replies
    RKennedy9064
    @RKennedy9064
    I've got another quick question if someone has some spare time. What's the proper way to implement a custom route in a JsonApiController? Essentially I want to create a route that I can query to get the current users information after they've logged in with a basic route like api/v1/me, that just returns info for the current user. I know I can override the controller methods like GetAsync, but I don't see an example of adding a custom route to a JsonApiController. Is something like that even possible? Worst case I can just make a normal ApiController and create the /me route there, but was hoping I could just add it to my existing Users controller.
    2 replies
    taccommandeur
    @taccommandeur
    Hi, I have an issue with hydration of a field that does some prosessing when setting:
    public class User : Identifiable<Guid>
    {
        [Key]
        public override Guid Id { get; set; }
    
        [Attr]
        public string Password
        {
            get => "";
            set => FillPassword(value);
        }
    
        [JsonIgnore]
        public string PasswordHash { get; set; }
    
        public void FillPassword(string password)
        {
            PasswordHash = BCryptNet.HashPassword(password);            
        }
    }
    When passing the password attribute in the body, the FillPassword method is called and I see that the PasswordHash is filled. But the value for the password hash is not persisted in the db.
    Is the above something that is not possible with this package?
    taccommandeur
    @taccommandeur
    public override Task OnWritingAsync(User resource, OperationKind operationKind, CancellationToken cancellationToken)
    {
        var test = ""; // If I put a breakpoint on this line I can see that resource.PasswordHash is null
    
        return base.OnWritingAsync(resource, operationKind, cancellationToken);
    }
    I also have a resource definition, with the above method, which is triggered.
    taccommandeur
    @taccommandeur

    Also, when I do this in a dummy controller:

    User user = new() { Password = "somepassword",  Email = "test@test.te" };
    _userRepository.Save(user);

    Then the password hash is persisted in the db

    Bart Koelman
    @bart-degreed
    The User instance from the incoming request body is not the one being saved. See the resource definition docs on when attribute values are copied.