dotnet / efcore

EF Core is a modern object-database mapper for .NET. It supports LINQ queries, change tracking, updates, and schema migrations.
https://docs.microsoft.com/ef/
MIT License
13.78k stars 3.19k forks source link

Conventions should honor [MetadataType] #14544

Open bricelam opened 5 years ago

bricelam commented 5 years ago

Buddy classes are back!

[MetadataType(typeof(PostMetadata))]
partial class Post
{
}

class PostMetadata
{
    [StringLength(256)]
    public string Title { get; set; }
}
smitpatel commented 5 years ago

ref: https://docs.microsoft.com/en-us/dotnet/api/system.componentmodel.dataannotations.metadatatypeattribute?view=netframework-4.7.2#remarks

For example, in the associated class you can apply the RequiredAttribute attribute to a data field. This enforces that a value is provided for the field even if this constraint is not required by the database schema.

Should it apply to model building?

bricelam commented 5 years ago

They did in EF6

bergi9 commented 4 years ago

Any update? Are there any workaround till it got implemented?

ajcvickers commented 4 years ago

@bergi9 This issue is in the Backlog milestone. This means that it is not planned for the next release (EF Core 5.0). We will re-assess the backlog following the this release and consider this item at that time. However, keep in mind that there are many other high priority features with which it will be competing for resources.

The workaround is to configure the model using data annotations on the entity types themselves, or just the model building API in OnModelCreating.

bergi9 commented 4 years ago

Annotations on models is not possible for me because my models are t4 generated with partial keyword. So I’m using the model building API till it get implemented.

bricelam commented 4 years ago

Note to implementer: The AttributeProvider class in EF6 took care of this (via AssociatedMetadataTypeTypeDescriptionProvider)