EntityFramework.Docs icon indicating copy to clipboard operation
EntityFramework.Docs copied to clipboard

Add data annotation examples, clarify what should be used as a string

Open piskov opened this issue 1 year ago • 0 comments

1. Samples for both modeling approaches

Section would benefit providing samples both with data annotations and model building API. Currently there is only model building API. Referenced data annotations is a separate page and thus is less useful (context switching and different examples). It would be much more beneficial to have tabbed versions of both examples like it is implemented here.

May be not as fancy as selectable tabs, but mere two paragraphs of code for both approaches one below the other would suffice.

2. Sample for composite foreign key

Even on referenced data annotations page there is no info about composite foreign keys there. No one could guess that you can write something like ForeignKey("id1, id2"). Also current API is not consistent between primary key (which has params) and foreign key (which has only one string which one could think is only for one name) which adds additional confusion of thinking you could not have more than one property with data annotations.

3. Clarification about names used as strings in keys (primary, foreign, indices, etc.)

Suppose you have a code like this for a renamed column:

class Item
{
    [Column("ActualNameInDb")]
    public string Property {get; set;}
}

Currently it’s not obvious what name should one use for mapping attributes. One could ask should it be Index("Property") or Index("ActualNameInDb")(Index is just an example, same holds for PrimaryKey and others alike).

I think it would be beneficial to clarify this exact case as a separate example as renaming is very much common.

—-

Document Details

Do not edit this section. It is required for learn.microsoft.com ➟ GitHub issue linking.

piskov avatar Oct 22 '23 19:10 piskov