Mixing Fluent API and DataAnnotations in EF code first

后端 未结 3 1624
北恋
北恋 2020-11-29 10:20

While we mostly use fluent configuration for our code-first POCOs, we have found it useful to use data annotations for things like the table name, PKs, etc. since it makes i

3条回答
  •  情歌与酒
    2020-11-29 11:10

    I don't think it's a risk - as both things have equivalent counterparts for the most of it.

    But, personally, when I run into some sort of issues around structuring my entities - first thing I do is to remove annotations if any - and move all to fluent.

    Which over time led me to use pretty much straight fluent configuration (also freeing my my objects of any ties with the Db 'state of mind')...

    IMO it is 'safer' but only in a way that you can do more and control things exactly as you'd want them. Also helps with keeping things consistent and in one place.

提交回复
热议问题