marten
marten copied to clipboard
Cannot use .Duplicate on an array
If I create a Duplicate
field that is an array/list/IEnumerable the SQL functions that are generated are wrong and / or the code that calls them has the wrong type.
this.Schema.For<User>()
.SoftDeleted()
.Duplicate(u => u.MemberOf, configure: i => i.Method = IndexMethod.gin)
.Duplicate(u => u.PrimaryEmail);
In the above definition where MemberOf is of type List<string>
I get the following function declaration:
CREATE OR REPLACE FUNCTION public.mt_insert_user(arg_member_of jsonb, arg_primary_email varchar, doc JSONB, docDotNetType varchar, docId varchar, docVersion uuid, tenantid varchar) RETURNS UUID LANGUAGE plpgsql SECURITY INVOKER AS $function$
BEGIN
INSERT INTO public.mt_doc_user ("member_of", "primary_email", "data", "mt_dotnet_type", "id", "mt_version", "tenant_id", mt_last_modified) VALUES (arg_member_of, arg_primary_email, doc, docDotNetType, docId, docVersion, tenantid, transaction_timestamp());
RETURN docVersion;
END;
$function$;
The argument arg_member_of
is of type jsonb
, but when I call SaveChanges
I get the error function public.mt_insert_user(arg_member_of => text[], arg_primary_email => text, doc => jsonb, docdotnettype => character varying, docid => text, docversion => uuid, tenantid => character varying) does not exist
. Notice the type of arg_member_of
is text[]
, not jsonb
I have been able to resolve manually by changing the signature to take text[]
and use to_jsonb
inside the function, but presumably this should be handled?
I'm using latest v3 branch, v3.13.3
@barclayadam I know we've fixed a similar issue for arrays, but I don't remember anyone using List<T>
. Could you try using string[]
instead for your duplicated field in the meantime before this gets addressed?
https://github.com/JasperFx/marten/issues/1875 looked be a related issue.
I think* I may have added the array support but had not considered uuid[]
or jsonb
.
For this particular scenario why would you duplicate json to its own field?
This is fixed in V7 at the least.