EntityFramework-Reverse-POCO-Code-First-Generator icon indicating copy to clipboard operation
EntityFramework-Reverse-POCO-Code-First-Generator copied to clipboard

Incorrect configuration for image in SQLCE

Open statler opened this issue 5 years ago • 11 comments
trafficstars

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();

statler avatar Dec 18 '19 09:12 statler

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

sjh37 avatar Dec 18 '19 12:12 sjh37

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?

sjh37 avatar Dec 22 '19 12:12 sjh37

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

ErikEJ avatar Dec 23 '19 09:12 ErikEJ

EF 6 thanks Erik

statler avatar Dec 27 '19 06:12 statler

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

statler avatar Dec 27 '19 06:12 statler

Yes, but #179 is EF6, not Core.

ErikEJ avatar Dec 27 '19 07:12 ErikEJ

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.

ErikEJ avatar Dec 27 '19 08:12 ErikEJ

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

statler avatar Dec 27 '19 08:12 statler

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

.IsMaxLength(); 

ErikEJ avatar Dec 27 '19 08:12 ErikEJ

Yes. Completely agree.

statler avatar Dec 27 '19 08:12 statler

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

sjh37 avatar Dec 27 '19 12:12 sjh37