SpiritBob
SpiritBob

Reputation: 2682

Why doesn't DbSets work when initialized as a field, rather than as a property?

For some reason when you do something like DbSet<TSource> blabla; rather than DbSet <TSource> Property_Blabla {get; set;} , when doing migrations it never understands or spots the DbSets? Why is that the case, can someone clarify?

Thank you!

Upvotes: 0

Views: 65

Answers (1)

David Browne - Microsoft
David Browne - Microsoft

Reputation: 89191

Because EF was designed that way. I can speculate that it's because using fields instead of properties is generally considered bad practice. Or that it would complicate the design and confuse developers. So adding the ability to use fields wouldn't be worth the effort.

But there's no fundamental reason that entities are declared using properties of type DbSet<T> instead of some other convention.

Upvotes: 2

Related Questions