datacontext

Entity Framework Thread Safety

女生的网名这么多〃 提交于 2019-11-27 01:32:35
The context objects generated by Entity Framework are not thread-safe. What if I use two separate entity contexts, one for each thread (and call SaveChanges() on each) - will this be thread-safe? // this method is called from several threads concurrently public void IncrementProperty() { var context = new MyEntities(); context.SomeObject.SomeIntProperty++; context.SaveChanges(); } I believe entity framework context implements some sort of 'counter' variable which keeps track of whether the current values in the context are fresh or not. With the code above - called from separate threads - do I

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

与世无争的帅哥 提交于 2019-11-26 22:31:52
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? Sadegh Unlike most types which implement IDisposable, DataContext doesn't really need disposing - at least not in most cases. I asked Matt Warren about this design decision, and here was his response: There are a few reasons we implemented

Simulating Cross Context Joins--LINQ/C#

只愿长相守 提交于 2019-11-26 22:09:00
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_ACCOUNT_NUMBER.ToString() == accountID join app in _baseDataContext.Account.APPLICATIONs on a.GUID_ACCOUNT_ID

page.DataContext not inherited from parent Frame?

佐手、 提交于 2019-11-26 18:55:53
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? To answer your question about documentation of this behavior: It's not Microsoft documentation, but I have a couple of WPF books that both

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

谁说胖子不能爱 提交于 2019-11-26 16:32:40
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 something like this: <ItemsControl ItemsSource="{Binding Markers"}> <ItemsControl.ItemTemplate> <DataTemplate

LinqToSql declare and instantiate DataContext best practice?

放肆的年华 提交于 2019-11-26 14:15:47
问题 What's the best practice in terms of setting up my DataContext for easy access in my extended LinqToSql classes? For example, I have a "User" entity in my dbml and I want to add methods to that class like so: Partial Public Class User Public Function GetUser(ByVal UserID as Integer) as User 'Do Work End Function End Class In order to access my DataContext I'd have to declare it inside the method like so: Partial Public Class User Public Function GetUser(ByVal UserID as Integer) as User Dim dc

Silverlight - Setting DataContext in XAML rather than in constructor?

走远了吗. 提交于 2019-11-26 13:07:17
问题 How can I set the DataContext on my Grid in XAML, instead of in the constructor? Here is how I do it in the constructor (LayoutRoot is the XAML Grid defined in the XAML): this.LayoutRoot.DataContext = this.HPVM; I would prefer to do it right in the XAML, but I do not know how to reference the HPVM object in XAML. HPVM is a public property on the USerControl class. It works fine as listed above, but again, I just want to know how to properties of the UserControl class in XAML, rather than

Datacontext conflicts

混江龙づ霸主 提交于 2019-11-26 12:33:52
问题 <UserControl x:Class=\"WatermarkTextBox\" xmlns=\"http://schemas.microsoft.com/winfx/2006/xaml/presentation\" xmlns:x=\"http://schemas.microsoft.com/winfx/2006/xaml\" xmlns:d=\"http://schemas.microsoft.com/expression/blend/2008\" xmlns:mc=\"http://schemas.openxmlformats.org/markup-compatibility/2006\" mc:Ignorable=\"d\" d:DesignHeight=\"30\" d:DesignWidth=\"250\"> <UserControl.Resources> <BooleanToVisibilityConverter x:Key=\"BooleanToVisibilityConverter\" /> </UserControl.Resources> <Border>

UserControl&#39;s DataContext

和自甴很熟 提交于 2019-11-26 10:43:07
问题 I\'m creating a UserControl I want to use something like this: <controls:ColorWithText Color=\"Red\" Text=\"Red color\" /> So far, I\'ve implemented similar controls like this: <UserControl x:Class=\"Namespace.ColorWithText\" Name=\"ThisControl\"> <StackPanel Orientation=\"Horizontal\" > <Border Width=\"15\" Height=\"15\" Background=\"{Binding Color, ElementName=ThisControl}\" /> <TextBlock Text=\"{Binding Text, ElementName=ThisControl}\" /> </StackPanel> </UserControl> where Color and Text

Entity Framework Thread Safety

社会主义新天地 提交于 2019-11-26 09:39:14
问题 The context objects generated by Entity Framework are not thread-safe. What if I use two separate entity contexts, one for each thread (and call SaveChanges() on each) - will this be thread-safe? // this method is called from several threads concurrently public void IncrementProperty() { var context = new MyEntities(); context.SomeObject.SomeIntProperty++; context.SaveChanges(); } I believe entity framework context implements some sort of \'counter\' variable which keeps track of whether the