Serenity: Custom RetrieveResponse Without EntityId

Created on 26 Mar 2020  路  5Comments  路  Source: serenity-is/Serenity

Hello,
I need to create retrieveresponse without entityid. but I pass another id in MyRow. I can't retrieve the value in my project.
For Example, MyRow is Investigation, this entityId is InvestigetionId,
And my other id is AdmissionId.

Most helpful comment

here is list of methods

https://github.com/volkanceylan/Serenity/wiki/Serenity-Framework:-Repository-overridable-methods-and-calling-sequence

here is example it relates to List, not Retrieve but you can do something like that with Retrieve

private class MyListHandler : CustomListRequestHandle<MyRow> { }

public class CustomListRequestHandle<TRow> : ListRequestHandler<TRow> where TRow : Row, new()
{
    protected override void ApplyFilters(SqlQuery query)
    {
        base.ApplyFilters(query);

        if (Request is Common.MyBaseListRequest customRequest)
        {
            if (customRequest.EnableOnlyNextPreviousMode)
            {
                query.ApplySkipTakeAndCount(this.Request.Skip, this.Request.Take, this.Request.ExcludeTotalCount || DistinctFields != null);

                // Setting CountRecords to false stops the count(*) query from running
                query.CountRecords = false;
            }
        }                
    }
}

All 5 comments

You might call the List method instead and take the first record.

For example,

            var entity = new SomeRepository().List(connection, new ListRequest
            {
                Criteria = new Criteria(nameof(SomeRow.AdmissionId)) == 5,
                Take = 1
            }).Entities.FirstOrDefault();

In repository.cs you can custom Retrieve/List... like you want, they have some methods that you can overwrite

here is list of methods

https://github.com/volkanceylan/Serenity/wiki/Serenity-Framework:-Repository-overridable-methods-and-calling-sequence

here is example it relates to List, not Retrieve but you can do something like that with Retrieve

private class MyListHandler : CustomListRequestHandle<MyRow> { }

public class CustomListRequestHandle<TRow> : ListRequestHandler<TRow> where TRow : Row, new()
{
    protected override void ApplyFilters(SqlQuery query)
    {
        base.ApplyFilters(query);

        if (Request is Common.MyBaseListRequest customRequest)
        {
            if (customRequest.EnableOnlyNextPreviousMode)
            {
                query.ApplySkipTakeAndCount(this.Request.Skip, this.Request.Take, this.Request.ExcludeTotalCount || DistinctFields != null);

                // Setting CountRecords to false stops the count(*) query from running
                query.CountRecords = false;
            }
        }                
    }
}

thanks

Was this page helpful?
0 / 5 - 0 ratings

Related issues

chintankukadiya18 picture chintankukadiya18  路  3Comments

Akarsh03 picture Akarsh03  路  3Comments

GitHubOrim picture GitHubOrim  路  3Comments

Shraddha996 picture Shraddha996  路  3Comments

newyearsoft picture newyearsoft  路  3Comments