简体   繁体   中英

Is there a link between the WPF (XAML) DataContext and the Entity Framework Context object?

I try to understand the Mixrosoft mind. Is there a link between the WPF (XAML) DataContext and the Entity Framework Context object? Why calling both of them Context? Is the Entity Framework Context object a WPF DataContext?

No, they are not the same.
WPF DataContext is any object, whose data can be bound to WPF controls.
Entity Framework ObjectContext (DbContext) is a "facade" of ORM.
You can work with WPF without EF and use as DataContext anything. The same, you can use EF and display your data in WinForms... or not display them at all.

I think, MS called them "-Context" because they use in contextual manner for their respective use cases: "Show the data in UI" and "Manipulate with data in database".

No, there is no link between them. they both contain the word Context , because they both provide a context.
DataContext provides a context where controls can bind to, ObjectContext provides a context for working with a data source (like a database).

No.

The term context is a common term in english and usually is used to define a set a things that set the conditions or boundary of something. For example in the context of programming a function is peice of code that returns a value, while in the context human activity it could be the job that a person does.

So for data binding in WPF the context is the data (or objects) that are being bound to the presentation. The EF context is the set of things that look after the connection to the data source.

Frankly you'll find most software has context objects all over the place :-)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM