dotnet / dotnet/EntityFramework.Docs

What does MaxLengthAttribute (or HasMaxLength) do in Primitive Collections?

Open
#4,575 1 comment 0 reactions 0 assignees View on GitHub
area-model-building
Dominant language
Mermaid
Stars
1.7k
Forks
2k
Avg merge
7d 23h
Merged PRs (30d)
16

Description

On the [What's New in EF Core 8](https://learn.microsoft.com/nl-nl/ef/core/what-is-new/ef-core-8.0/whatsnew#primitive-collections) webpage, Primitive Collections section, there are some examples on how the Primitive Collections work.

In these examples the MaxLengthAttribute and HasMaxLength is used on non-string columns. This is also the case for Unicode by the way.

```C#
modelBuilder
.Entity()
.Property(e => e.Booleans)
.HasMaxLength(1024)
.IsUnicode(false);
```
where Booleans is a list of booleans.

```C#
[MaxLength(2500)]
[Unicode(false)]
public uint[] UnsignedInts { get; set; }
```
UnsignedInts is a list of numbers.

**Question: In these examples, what does MaxLength do? Is this the maximum number of items in the list? Does it serve any purpose at all (also for Unicode?**

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.