datacontext

Access DataContext behind IQueryable

心不动则不痛 提交于 2019-12-18 13:03:06
问题 Is it possible to access the DataContext object behind an IQueryable? If so, how? 回答1: DataContext is specific to LINQ to SQL, so presumably you're talking about LINQ to SQL queries? If so, there's no safe way to do this - you have to resort to a hack such as using reflection to retrieve the private "context" field of the underlying DataQuery object: static DataContext GetContext (IQueryable q) { if (!q.GetType().FullName.StartsWith ("System.Data.Linq.DataQuery`1")) return null; var field = q

Exceptions by DataContext

拥有回忆 提交于 2019-12-18 12:22:34
问题 I've been doing some searching on the internet, but I can't seem to find the awnser. What exceptions can a DataContext throw? Or to be more specific, what exceptions does the DataContext.SubmitChanges() method throw? EDIT For reference, here a List of possible known exceptions that could be thrown by the L2S DataContext: SqlException ChangeConflictException DuplicateKeyException ForeignKeyReferenceAlreadyHasValueException OutOfMemoryException (when not correctly disposing the DataContext) 回答1

How to get rid of StackOverflow Exception in DataContext InitializeComponent?

有些话、适合烂在心里 提交于 2019-12-18 07:06:10
问题 I am new to wpf c#, trying some sample application, the problem is when I mention DataContext in xaml the InitializeComponent is called recursively and is showing System.StackOverflowException' occurred in mscorlib.dll This is my XAML markup: <Window x:Class="Company1.MainWindow" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:local="clr-namespace:Company1" Title="MainWindow" Height="350" Width="525" > <Window

Why would reusing a DataContext have a negative performance impact?

点点圈 提交于 2019-12-17 22:42:05
问题 After a fair amount of research and some errors, I modified my code so that it creates a new DataContext each time the database is queried or data is inserted. And the database is queried frequently - for each of 250k transactions that are processed, the database is queried to obtain a customer id, department id, and category before the transaction is inserted. So now I'm trying to optimize the code as it was only processing around 15 transactions a second. I removed some extraneous queries

FrameworkElement`s DataContext Property does NOT inherit down the element tree

跟風遠走 提交于 2019-12-17 19:48:47
问题 Hello WPF Pros at least I hope some of you read this! DataContext is a property on FrameworkElement (base class for all WPF Controls) and is implemented as a DependencyProperty. That means all the descendant elements in the logical tree share the same DataContext. So the ContentControl should do it with its descendant elements right? I have a scenario where that is NOT the case and I would like to know WHAT is the cause of that misbehaviour ?! That you understand a bit more about it please

Multiple dataContext for one control - MVVM

北城以北 提交于 2019-12-17 19:44:55
问题 I am not sure if my question header represent exactly my problem, I will do the best to explain: I have a grid cell DataTemplate: (the grid belong to third party company but it`s not important for my question) <DataTemplate> <TextBlock> <Hyperlink Command="{Binding OpenLinkCommand}"> <Hyperlink.ToolTip> <TextBlock Text="{Binding Data.MapLink}"/> </Hyperlink.ToolTip> <TextBlock Text="{Binding Data.MapLink}" TextDecorations="underline"> </Hyperlink> </TextBlock> </DataTemplate> I want make this

attaching linq to sql datacontext to httpcontext in business layer

旧城冷巷雨未停 提交于 2019-12-17 18:43:39
问题 I need my linq to sql datacontext to be available across my business/data layer for all my repository objects to access. However since this is a web app, I want to create and destroy it per request. I'm wondering if having a singleton class that can lazily create and attach the datacontext to current HttpContext would work. My question is: would the datacontext get disposed automatically when the request ends? Below is the code for what I'm thinking. Would this accomplish my purpose: have a

Setting DataContext within UserControl is affecting bindings in parent

谁说我不能喝 提交于 2019-12-17 12:26:50
问题 I have a basic UserControl that sets its DataContext to itself for ease of binding: <UserControl x:Class="MyControlLib.ChildControl" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" DataContext="{Binding RelativeSource={RelativeSource Self}}"> </UserControl> This is used in a parent XAML file like this: <UserControl x:Class="MyControlLib.ParentControl"

Setting DataContext within UserControl is affecting bindings in parent

可紊 提交于 2019-12-17 12:25:19
问题 I have a basic UserControl that sets its DataContext to itself for ease of binding: <UserControl x:Class="MyControlLib.ChildControl" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" DataContext="{Binding RelativeSource={RelativeSource Self}}"> </UserControl> This is used in a parent XAML file like this: <UserControl x:Class="MyControlLib.ParentControl"

Treating multiple tabs as separate Views with separate ViewModels in WPF

為{幸葍}努か 提交于 2019-12-14 03:53:58
问题 In WPF, I have one Window containing a TabControl with four TabItems. Each TabItem has a Grid: <TabItem Header="Input" Name="tabItem1"> <Grid></Grid> </TabItem> In my codebehind I need to specify a datacontext pointing to a ViewModel. Rather than having one ViewModel to handle all four tabs, I would like a ViewModel for each Tab. This would mean having different DataContexts for each time. Is there a way to achieve this in a clean way? 回答1: You can set DataContext in XAML only by declaring