Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support for array types #15

Closed
roji opened this issue Apr 14, 2016 · 13 comments
Closed

Support for array types #15

roji opened this issue Apr 14, 2016 · 13 comments
Assignees
Labels
enhancement New feature or request
Milestone

Comments

@roji
Copy link
Member

roji commented Apr 14, 2016

From @eBerdnA on December 29, 2015 15:53

I just noticed that scaffolding a table which includes a column with datatype bytea[] can't be scaffolded. The following warning is generated.

Could not find type mapping for column 'public.File.md5Hash' with data type '_bytea'. Skipping column.
Unable to scaffold the index 'File_md5Hash_key' because one of the properties it contains could not be scaffolded.

I'm using a simple table like this.

CREATE TABLE "File"
(
  "FileId" serial NOT NULL,
  "Filename" character varying(255) NOT NULL,
  "md5Hash" bytea[] NOT NULL,
  CONSTRAINT "File_pkey" PRIMARY KEY ("FileId"),
  CONSTRAINT "File_md5Hash_key" UNIQUE ("md5Hash")
)
WITH (
  OIDS=FALSE
);
ALTER TABLE "File"
  OWNER TO postgres;

Does this happen due to a limitation of the EntityFramework or due to an issue of npgsql?

Copied from original issue: npgsql/npgsql#926

@roji roji self-assigned this Apr 14, 2016
@roji
Copy link
Member Author

roji commented Apr 14, 2016

This should definitely be supported, I'll take a look.

@roji roji added bug Something isn't working ef core labels Apr 14, 2016
@roji
Copy link
Member Author

roji commented Apr 14, 2016

This is actually a wider problem I ran into a while ago - how should array types be handled. In general, EF7 treats such properties as navigation properties; we need to check what happens if an entity has an array property (or more generally an IList property) over a type that isn't itself an entity. If these are simply ignored by the EF7 core then we can probably map these to PostgreSQL arrays.

Either way we need to look at how EF7 normally handles this before tackling reverse engineering.

@roji roji removed the ef core label Apr 19, 2016
@roji roji changed the title EF7 support for array types Support for array types Apr 23, 2016
@roji roji added enhancement New feature or request and removed bug Something isn't working labels May 15, 2016
@tuoxieyz
Copy link

Is this feature supported now ? I tried just now but still got an error :
{"The property 'Merchandise.PictureUris' could not be mapped, because it is of type 'String[]' which is not a supported primitive type or a valid entity type. Either explicitly map this property, or ignore it."}

The 'PictureUris' is a column,of which the datatype is text[].

@roji
Copy link
Member Author

roji commented Jun 30, 2016

Nope, still not supported, there were more important things to do. I hope to take a look soon.

@roji roji modified the milestone: 1.1.0 Jul 1, 2016
@roji roji added the blocked label Jul 2, 2016
@roji
Copy link
Member Author

roji commented Jul 2, 2016

dotnet/efcore#5955

@roji roji removed the blocked label Jul 5, 2016
@roji
Copy link
Member Author

roji commented Jul 5, 2016

I've committed support for arrays, I can see tables being created with int[] and can read and write.

Still left:

  • More testing (change detection, queries, and updates)
  • Scaffolding support

roji added a commit that referenced this issue Jul 7, 2016
Does not include scaffolding

Work on #15
@tuoxieyz
Copy link

tuoxieyz commented Jul 8, 2016

Thank you for doing this great job,I tried and it takes effect. My English is very poor, so I’d like to express my gratitude with Chinese —— 谢谢!

@roji
Copy link
Member Author

roji commented Jul 8, 2016

@tuoxieyz thanks for the kinds words :)

The feature isn't completely done yet, but the basics are there. Please test and let me know of any issues!

@NickAtEbsco
Copy link

I'm still not able to insert with text arrays using the latest 1.0.2 off nuget.org. I've tried using string[], List and two different sql statements to manually insert with text arrays and they all fail. I created a repo to illustrate this here. https://github.com/NickAtEbsco/PostgresTextArray

@roji
Copy link
Member Author

roji commented Oct 5, 2016

As the milestone shows, this has only been done for the 1.1.0 release, not 1.0.2. 1.1.0 is scheduled for release in November. Until then, if you're brave you can try the 1.1.0 CI nuggets from the Npgsql unstable feed.

@NickAtEbsco
Copy link

I just pulled it in and it appears to be working. I'll use that until November. Thanks for the response.

@roji
Copy link
Member Author

roji commented Oct 6, 2016

Great to know it works for you, please let me know if you encounter any issues.

@andersonsalgado
Copy link

Hello everyone. I'm trying to map a byte field [] to store an image, however I'm getting the error:

Microsoft.EntityFrameworkCore.Infrastructure [10403]
       Entity Framework Core 2.1.1-rtm-30846 initialized 'TeAjudoContext' using provider 'Npgsql.EntityFrameworkCore.PostgreSQL' with options: None
System.InvalidOperationException: No mapping to a relational type can be found for property 'prjTeAjudoCore.Models.EstabelecimentoCredito.ProvanteTransfer' with the CLR type 'Nullable []'.

My Field:

[Column("ESCR_BT_COMPROVANTE", TypeName = "bytea")]
[DisplayName("Comprovante de Transferência")]
public byte[] ComprovanteTransferencia { get; set; }

can you help me?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

4 participants