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
1 Answer 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
Morten Bork
1,67714 silver badges25 bronze badges
Sign up to request clarification or add additional context in comments.
5 Comments
LuisDSS
Tried this (used exactly the same code), dropped the database and it set it to 900 too
Morten Bork
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.
LuisDSS
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.
siggemannen
Setting varbinary as pk is... not a good idea in 99.99% of cases. You should rethink your approach
LuisDSS
Not my design, I completely agree.
Explore related questions
See similar questions with these tags.
default