0

I am working with the code first approach, here is the POCO object I am using

public class Fotografia
{
 // Fotografía
 [Display(Name = "Fotografía")]
 public required byte[] fotografia { get; set; }
}

I want to set the max value for the varbinary value it creates, currently I've read other posts which specify that this way it should set by default the max value but my code generates

fotografia (PK, varbinary(900), not null)

Which is smaller than what I need to use

asked Oct 23, 2023 at 16:50

1 Answer 1

1

Simply adding the [MaxLength] annotation doesn't work? Like this?

public class Fotografia
{
 // Fotografía
 [Display(Name = "Fotografía")]
 [MaxLength]
 public required byte[] fotografia { get; set; }
}
answered Oct 23, 2023 at 17:21
Sign up to request clarification or add additional context in comments.

5 Comments

Tried this (used exactly the same code), dropped the database and it set it to 900 too
would you be willing to find the spot in your migration file, where it defines this property? as that will help us narrow down where the problem is.
I've found the issue, the varbinary is set as part of the key causing a total of 900 bytes to be the maximum value allowed due to MS SQL Server properties.
Setting varbinary as pk is... not a good idea in 99.99% of cases. You should rethink your approach
Not my design, I completely agree.

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.