sjh37 / EntityFramework-Reverse-POCO-Code-First-Generator

EntityFramework Reverse POCO Code First Generator - Beautifully generated code that is fully customisable. This generator creates code as if you reverse engineered a database and lovingly created the code by hand. It is free to academics (you need a .edu or a .ac email address), not free for commercial use. Obtain your licence from
https://www.reversepoco.co.uk/
Other
704 stars 231 forks source link

Incorrect configuration for image in SQLCE #564

Open statler opened 4 years ago

statler commented 4 years ago

When generating the configuration for SqlCe image, the following is

Property(x => x.Logo)
    .HasColumnName(@"Logo")
    .HasColumnType("image")
    .IsOptional()
    .HasMaxLength(null);

This throws an exception when trying to write any value to a table in which this property exists.

The following however, does work.

Property(x => x.Logo)
    .HasColumnName(@"Logo")
    .HasColumnType("image")
    .IsOptional()
    .IsMaxLength();
sjh37 commented 4 years ago

Just about to jump on a plane. I'll look into this later.

sjh37 commented 4 years ago

Is this for EF6 or .Net Core ? Take a look at case #179 which the solution is for using .HasMaxLength(null); for images > 4000 bytes.

.IsMaxLength() is used for ntext column types.

@ErikEJ Have you ever heard of .HasMaxLength(null); throwing an exception when trying to write any value to a table in which this property exists?

ErikEJ commented 4 years ago

We need to know if this is for EF Core or EF 6.

statler commented 4 years ago

EF 6 thanks Erik

statler commented 4 years ago

BTW - this is exactly the issue listed by Listenreich in #179. Images >4000 bytes

ErikEJ commented 4 years ago

Yes, but #179 is EF6, not Core.

ErikEJ commented 4 years ago

OK, so now it is EF 6 after all??? 😕

This throws an exception when trying to write any value to a table in which this property exists.

@statler No, I have never heard about this, so please share the full stack trace of the exception, and your table schema.

statler commented 4 years ago

Yes. Ef6. I had a typo and edited it almost immediately. Did you refer only to the email? Sorry about that.

Won't be able to get the stack trace quickly. Away from my PC on leave. But it is easy to replicate, just try to map an image greater than 4kb with the default code - e.g. HasMaxLength(null). You will get the error per #179

ErikEJ commented 4 years ago

Well, in that case the generated code should most likely jsúst be changed to be:

.IsMaxLength(); 
statler commented 4 years ago

Yes. Completely agree.

sjh37 commented 4 years ago

Thanks both. I'll update the code when I get back from holiday.