AutoQueryGrid Edit Forms trying to use wrong QueryDb for references

It is possible to to specify with Request should be used for on blazor auto Edit Forms?

Let says i have the following example

class MyEntity {
....
[References(typeof(Person))]
 public int PersonId {get;set;}
}
class QueryPerson: QueryDb<Person> {}
class QueryPerson2: QueryDb<Person, CustomResponse> {}

When i try to select a person from the auto edit form generated by blazor AutoQueryGrid, it try use QueryPerson2 causing and exception because it can’t cast CustomResponse to Person.
It is possible to specify somewhere to use only QueryPerson?

thanks

Are you referring to <AutoEditForm /> or <AutoQueryGrid>?

Not clear on what’s making the query that has the issue. Can you show your Markup component usage that’s causing the issue along with any StackTraces.

<AutoQueryGrid Model="ListingSuggestion"
           Apis="Apis.AutoQuery<QueryListingSuggestions, CreateListingSuggestion, UpdateListingSuggestion, DeleteListingSuggestion>()"></AutoQueryGrid>
public class ListingSuggestion : AuditBase
{
   [AutoIncrement]
   [PrimaryKey]
   public long Id { get; set; }
       
   [ValidateMaximumLength(255)]
   public string Description { get; set; }

   [Required]
   [References(typeof(AppUser))]
   [Ref(Model = nameof(AppUser), RefId = nameof(AppUser.Id),  RefLabel = nameof(AppUser.UserName))]
   public int SuggesterId { get; set; }

   public long ListingId { get; set; }

   [Reference]
   public Listing Listing { get; set; }
}
   

Then i have two autoquery implementations

[ValidateIsAdmin]
[ValidateIsAuthenticated]
public class QueryAppUsers : QueryDb<AppUser>
{    
}

[ValidateIsAuthenticated]
[ValidateIsAdmin]
public class QueryAllChefs : QueryDb<AppUser, ChefBasicInfo>
{
    public int? Id { get; set; }
}

I think is trying to use QueryAllChefs on the auto generated UI as i get this error, when trying to pick a value for SuggesterId

Ok it’s the ModalLookup having to use an AutoQuery API for its lookup and choosing the API with a different Model Type, which could be fixed in this commit:

This change is now available from v6.61+ that’s now available on MyGet.

Still getting the same error.

It seem that Query is null here, instead QueryInto is Populated with QueryAllChefs

public QueryBase QueryRequest<Model>() => (Query ?? QueryInto).CreateInstance<QueryBase>();

Also i’m seeing this strange issue AppUser repeated multiple times

This only happens if i reload the page while in edit mode

https://localhost:5001/listings/suggestions?edit=1

I think there also a new issue on 6.6.1

if i try to refresh a page url after restarting the dotnet process i get the following error

NullReferenceException: Object reference not set to an instance of an object.
ServiceStack.AppMetadataUtils.GetCache(AppMetadata app) in MetadataTypes.cs
ServiceStack.AppMetadataUtils.GetType(AppMetadata app, string name) in MetadataTypes.cs
ServiceStack.Blazor.Components.Tailwind.LookupInput.get_Icon() in LookupInput.razor.cs
ServiceStack.Blazor.Components.Tailwind.LookupInput.BuildRenderTree(RenderTreeBuilder __builder) in LookupInput.razor

I think there is also another minor issue, this worked on 6.6.0, calling ApiFormAsync now returns Not authenticated

Api = await ApiFormAsync<ListingPhoto>(request, formData);

I have made a repro for the first issue

nukedbit/MultipleQueryDbRepro (github.com)

By adding the following the issue is reproduced


public class QueryCoupons2Response
{
    public string Id { get; set; }
    public string Description { get; set; }
    public int Discount { get; set; }
    public DateTime ExpiryDate { get; set; }
}

[Tag("bookings"), Description("Find Coupons")]
[Route("/coupons", "GET")]
public class QueryCoupons2 : QueryDb<Coupon,QueryCoupons2Response>
{
    public string Id { get; set; }
}

thx for the repro, I’ve reverted the previous change in the latest v6.6.1+ on MyGet which should now resolve the correct API by default.

You shouldn’t need it for this but you can explicitly specify which AutoQuery API to use with QueryType, e.g:

[Ref(..., QueryType=typeof(QueryCoupons))]

Can you please check if the other issues still persist and if they do, let me know steps to repro, thx.

1 Like

Great, now it works fine, while i not need it now QueryType is going to be a usefull addition for some projects.

If i manage to repro the other issues i will let you know, indeed they are very strange

1 Like