jwaliszko / ExpressiveAnnotations

Annotation-based conditional validation library.
MIT License
351 stars 124 forks source link

Adding annotations to DTO triggers code first entity framework migration #195

Open mprigge opened 5 years ago

mprigge commented 5 years ago

I'm running into a very strange problem I'm having very little luck explaining, so I thought I might throw it out here in case you can think of any reason why this might occur.

I have a core library that implements a code first EF6 context which is then referenced by two web projects which utilize the context. Another shared library defines some common DTOs which are used by some external client libraries -- this library is referenced by the core and web projects as well but references very little otherwise. None of these DTOs are EF entities.

I am experimenting with adding Expressive Annotations to this shared library -- to apply the same validation on these DTOs. To do this, I referenced the ExpressiveAnnotations.dll nuget in the shared library which then allows me to decorate properties of the DTOs as necessary.

However - the super weird thing is that doing this causes entity framework to believe that the data model has changed and to prompt me to create a code first migration. To be clear, the DTOs I'm decorating are in no way involved in the context nor referenced as nav properties or anything else. I have no idea how simply doing this is causing EF to scoop them up and believe that it needs to do anything. More confusing, generating a migration produces empty Up/Down migrations which doesn't even give me a hint of what it thinks the problem is.

So yeah - this is a "flush the toilet and the TV shuts off" sorta situation, but I figured I'd ask here in case this seems familiar in any way.