datacontext

How to make Entity Framework Data Context Readonly

北城以北 提交于 2019-11-26 08:46:04
问题 I need to expose an Entity Framework Data Context to 3rd party plugins. The purpose is to allow these plugins to fetch data only and not to let them issue inserts, updates or deletes or any other database modification commands. Hence how can I make a data context or entity readonly. 回答1: In addition to connecting with a read-only user, there are a few other things you can do to your DbContext. public class MyReadOnlyContext : DbContext { // Use ReadOnlyConnectionString from App/Web.config

C# Linq-to-Sql - Should DataContext be disposed using IDisposable

断了今生、忘了曾经 提交于 2019-11-26 08:25:24
问题 I have several methods that deal with DB and all of them start by calling FaierDbDataContext db = new FaierDbDataContext(); Since the Linq2Sql DataContext object implements IDisposable, should this be used with \"using\"? using (FaierDbDataContext db = new FaierDbDataContext()) { // use db here } What are the implications of using it one way or another? 回答1: Unlike most types which implement IDisposable, DataContext doesn't really need disposing - at least not in most cases. I asked Matt

Simulating Cross Context Joins--LINQ/C#

北战南征 提交于 2019-11-26 08:13:15
问题 Here\'s the issue: I have 2 data contexts that I would like to do a join on. Now I know that LINQ doesn\'t allow joins from one context to another, and I know that 2 possible solutions would be to either create a single datacontext or to have 2 seperate queries (which is what I\'m doing for now). However what I would like to do is to \"simulate\" a join. Here\'s what I\'ve tried. using (var _baseDataContext = Instance) { var query = from a in _baseDataContext.Account.ACCOUNTs where a.STR

page.DataContext not inherited from parent Frame?

ぃ、小莉子 提交于 2019-11-26 07:38:47
问题 I have a Page page in a Frame frame , with frame.DataContext = \"foo\" . (page.Parent as Frame).DataContext is \"foo\" . ok BindingExpression for page.DataContext is null (also forced with ClearValue). ok page.DataContext is null . but I expected \"foo\"! Why isn\'t the DataContext inherited? As far as I understand the Frame sandboxes the content. But I couldn\'t find any documentation of this behavior - can anyone point me to a place where this is mentioned? 回答1: To answer your question

WPF ContextMenu woes: How do I set the DataContext of the ContextMenu?

房东的猫 提交于 2019-11-26 04:48:57
问题 I am having some trouble figuring out how to set the correct DataContext on a ContextMenu . I have a collection of view models who are the source of an ItemsControl . Each view model has a collection of items which are also the source of another ItemsControl . Each item is used to draw image which has a ContextMenu . The MenuItems in that ContextMenu need to bind to a command on the view model, but the PlacementTarget of the ContextMenu is pointing to the individual item. My Xaml looks

WPF Databinding: How do I access the “parent” data context?

ぐ巨炮叔叔 提交于 2019-11-26 00:45:51
问题 I have a list (see below) contained in a window. The window\'s DataContext has two properties, Items and AllowItemCommand . How do I get the binding for the Hyperlink \'s Command property needs to resolve against the window\'s DataContext ? <ListView ItemsSource=\"{Binding Items}\"> <ListView.View> <GridView> <GridViewColumn Header=\"Action\"> <GridViewColumn.CellTemplate> <DataTemplate> <StackPanel> <TextBlock> <!-- this binding is not working --> <Hyperlink Command=\"{Binding