Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Conventions should honor [MetadataType] #14544

Open
Tracked by #24106 ...
bricelam opened this issue Jan 29, 2019 · 6 comments
Open
Tracked by #24106 ...

Conventions should honor [MetadataType] #14544

bricelam opened this issue Jan 29, 2019 · 6 comments

Comments

@bricelam
Copy link
Contributor

Buddy classes are back!

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

class PostMetadata
{
    [StringLength(256)]
    public string Title { get; set; }
}
@smitpatel
Copy link
Contributor

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
Copy link
Contributor Author

They did in EF6

@bergi9
Copy link

bergi9 commented Jan 19, 2020

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

@ajcvickers
Copy link
Member

@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
Copy link

bergi9 commented Jan 22, 2020

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
Copy link
Contributor Author

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

5 participants