Все вопросы: [datacontext]

130 вопросов

похожие теги:
1
голосов
2ответов
2284 просмотров

Linq to Sql - DataContext design issues and considerations in ASP.NET MVC application

I am using "Single data context per atomic operation" approach while using Linq to Sql in an ASP.NET MVC application. So far, I have been using a singleton datacontext, which I learnt has many issues, so I refactored the code to use single datacontext per atomic operation. An example of a contr...

0
голосов
2ответов
535 просмотров

Setting DataContext for the root element in XAML without the property element syntax

I was wondering if it's possible to write something like this: <Window ... xmlns definitions ... DataContext=<!--Create an instance here--> ></Window> Instead of this: <Window ... xmlns definitions ... > <Window.DataContext> <local:Cus...

0
голосов
3ответов
207 просмотров

Fetch Single Item Using DataContext

I'm doing the following: public MyItem FetchSingleItem(int id) { string query = "SELECT Something FROM Somewhere WHERE MyField = {0}"; IEnumerable<MyItem> collection = this.ExecuteQuery<MyItem>(query, id); List<MyItem> list = collection.ToList<MyItem>(); return li...

28
голосов
4ответов
42569 просмотров

How to instantiate DataContext object in XAML

I want to be able to create an instance of the DataContext object for my WPF StartupUri window in XAML, as opposed to creating it code and then setting the DataContext property programmaticly. The main reason is I don't need to access the object created externally and I don't want to have to wri...

0
голосов
1ответов
3113 просмотров

Set Window.DataContext to a declared property in the code-behind?

I want to achieve something like the following (Notice the DataContext property of the Window element): <Window x:Class="Window1" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" DataContext="{Binding MyDataCo...

48
голосов
5ответов
19793 просмотров

LINQPad, using multiple datacontexts

I am often comparing data in tables in different databases. These databases do not have the same schema. In TSQL, I can reference them with the DB>user>table structure (DB1.dbo.Stores, DB2.dbo.OtherPlaces) to pull the data for comparison. I like the idea of LINQPad quite a bit, but I ju...

2
голосов
2ответов
680 просмотров

Filter every call made by a DataContext when using LinQ Entities

I'm using logical delete in my system and would like to have every call made to the database filtered automatically. Let say that I'm loading data from the database in the following way : product.Regions How could I filter every request made since Regions is an EntitySet<Region> and no...

2
голосов
2ответов
4761 просмотров

WPF Databinding and Styles with MVVM

I have a problem with databinding on a style in WPF. The basic setup looks like this: <Style x:Key="{x:Type eo:Player}" TargetType="{x:Type eo:Player}"> <Style.Triggers> <DataTrigger Binding="{Binding Team}" Value="A"> <Setter Property="T...

3
голосов
1ответов
331 просмотров

Linq to SQL - Retain DataContext across post-backs?

I read Rick Strahl's post about DataContext lifetime management, and some of the other related questions on Stackoverflow. If they contained an answer to my question, I must have missed it. I generally follow the atomic approach and instantiate a DataContext for a unit of work when it is needed...

3
голосов
1ответов
5350 просмотров

WPF (MVVM): Wiring up viewModel to view in code-behind of Window?

I have been getting my feet wet with MVVM pattern for WPF and everything is working as it should.. But i am wiring up the viewmodel to my view datacontext from my codebehind of my window. Sure enough the point of MVVM is to get rid of code behind in windows... which it does great, so i am left...

1
голосов
3ответов
228 просмотров

Help me to understand MY`Using` and `DataContext`

Can someone please explain the below to me. First is how I call the method and the second bit is the LINQ Method. My curiousity stems from the fact that I get a context error if I un-comment the using portion. Why? I apparently do not fully understand using and context's. And I would like t...

1
голосов
3ответов
456 просмотров

LINQtoSQL Not saving to database,but changes show in app

Hey all, I have a linq app using C# express2008 and sqlserver express 2005 (mdf file connection) I followed the regular dml generation and vanilla datacontext. However i created a repository class to manage the Linq stuff. In using the functions, selecting data works fine, updating data works in...

0
голосов
1ответов
185 просмотров

Can I call a Method in one DataContext from another?

I have the below LINQ Query that I would like to suppliment with the Nurse Names. Unfortunately these are stored in a seperate DB and thus a seperate DataContext. How would I go about calling a method in my aspnetdbcontext from this query, which uses cmodatacontext? This is the method in aspne...

3
голосов
1ответов
5526 просмотров

How to change the DataContext of a button to the parents parent DataContext?

I have 2 Classes in WPF: Meeting People In meeting I have 2 ObservableCollections; AttendingMeeting and NotAttendingMeeting that contain People objects In the xaml the DataContext are set to Meeting, and I have 2 DataGrids (AttendingMeeting and NotAttendingMeeting) I need to add a Button t...

4
голосов
3ответов
1941 просмотров

C# add a Table<t> into an existing DataContext Instance</t>

Is it possible that I can add Table&lt;T&gt; dynamiclly to an exisitng DataContext Insance in LinqToSQL? Here is my case: I have several classsed which are using [Test] attribute to declared as Table, I want to allow user to create the corresponding SQL Server tables during run-time. I unde...

5
голосов
1ответов
1294 просмотров

Unit Testing, Linq to SQL and working around the Data Context

I have been looking at the following and it would appear that there are great benefits to be gained by using compiled queries... http://blogs.msdn.com/ricom/archive/2008/01/14/performance-quiz-13-linq-to-sql-compiled-query-cost-solution.aspx My problem is that I want to unit test my queries, bu...

0
голосов
1ответов
1332 просмотров

Binding to the selected TabItem content

I have a Window with two controls: control1 is a control that has a bunch of buttons that execute RoutedCommands; the second control is a TabControl that is bound to a list of documents. The TabControl ContentTemplate is a user control, control2, that has a ListView. I would like to bind the Data...

1
голосов
2ответов
1153 просмотров

Linq2Sql: re-Attaching entity to datacontext but not original datacontext problem

can anyone help? I have an issue with linq2sql and trying to Attach (update) an entity class through a datacontext, it complains its not the original context, this is true (see code below) ... I thought it was best practices to open the datacontext and close it when not needed? I basically have...

0
голосов
1ответов
2912 просмотров

DataContext's Connection string help

I have the following connection string: "Data Source=localhost\SQLEXPRESS;", it complains that '' is an invalid username. I can't quite remember the user name or password commands, nor can i remember if there's anything else i'm missing. Can someone help?

7
голосов
4ответов
1464 просмотров

How to handle nested datacontext in the BL?

public class TestBL { public static void AddFolder(string folderName) { using (var ts = new TransactionScope()) { using (var dc = new TestDataContext()) { var folder = new Folder { FolderName = folderName }; dc.Folde...

1
голосов
1ответов
2644 просмотров

How do I get the ColumnAttributes from a Linq.Table<tentity>?</tentity>

I'm trying to return attributes of columns from my DataContext. How can I pull out the ColumnAttribute meta data? public class MyDataContext : DataContext { public Table&lt;User&gt; User; public MyDataContext(string connection) : base(connection) { } } [Table(Name = "User")] public c...

1
голосов
1ответов
545 просмотров

DataContext name of WPFToolkit DataGrid shows in columns header background

I've got a strange problem with WPFToolkit DataGrid - after disabling AutoGenerateColumns, after adding only 1, narrow column, in the background of column headers appears full name of DataContext. It doesn't behave like a column - I can't neither resize or disable it. Previously I didn't know ab...

4
голосов
2ответов
3214 просмотров

Any way to improve Linq-To-SQL performance?

Please offer advice if you can... I've based my project on Linq-To-SQL, and the (almost) finished application has very poor performance. I've fired up the SQL Profiler many times to optimize the queries with LoadOptions to reduce the number of round-trips to the database server, but at the end o...

1
голосов
1ответов
633 просмотров

WPF DataContext for Child/Detail UserControl/View

I am new to C# and WPF, so please bear with me.. This isn't exactly a Master/Detail scenario, and could be why I am having problems, but generally, I am trying to figure out how to relate two sets of data that are not quite master/detail. To keep it simple, let's say I have two view/viewmodels ...

1
голосов
3ответов
2924 просмотров

Executing Method Against DataContext Returning Inserted ID

Is there any way to use DataContext to execute some explicit SQL and return the auto-increment primary key value of the inserted row without using ExecuteMethodCall? All I want to do is insert some data into a table and get back the newly created primary key but without using LINQ (I use explici...

2
голосов
1ответов
3390 просмотров

WPF DataContext vs ItemsSource Performance

Suppose we have an ItemsControl, which is bounded to a source. Is there any performance difference between ItemsControl.DataContext = resultSet; and ItemsControl.ItemsSource = resultSet; (In both cases correctly binded in XAML)

0
голосов
2ответов
1586 просмотров

Null Reference Exception In LINQ to SQL DataContext

I have a Null Reference Exception Caused by this code: var recentOrderers = (from p in db.CMS where p.ODR_DATE &gt; DateTime.Today - new TimeSpan(60, 0, 0, 0) select p.SOLDNUM).Distinct(); result = (from p in db.CMS where p.ORDER_ST2 == "SH" &amp;&amp; ...

0
голосов
1ответов
203 просмотров

Escape from DataContext

I have a window that get its data from another class that is passed as DataContext. But I now also want to do data binding within the window. The window looks as follows: &lt;Window x:Class="WpfApplication1.Window1" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:...

1
голосов
1ответов
452 просмотров

How to publish ASP.NET MVC site using datacontext to external SQL Server?

I am playing with MVC and I made a simple site. I have an seperate machine running SQL Server Express and on it I have a simple table called "Log". The table has ID, Timestamp, and Message fields. I added the database to my "Data Connections" on my "Server Explorer" section. In my MVC website I ...

5
голосов
4ответов
2406 просмотров

WPF - Why there is no "OnDataContextChanged" overridable method?

The FrameworkElement object has DataContextChanged event. However, there is no OnDataContextChanged method that can be overridden. Any ideas why?