datacontext

WPF DataContext syntax - Convert from C# to VB

Currently working through a Teach Yourself WPF tutorial. Usually I can mentally convert from C# to VB without any problem but this C# syntax is unfamiliar. How is it written in VB? Private void Button_Click(object sender, RoutedEventArgs e) { ((Person)DataContext).FirstName = "blah blah" } My usual fave online converters are choki...

How to dispose data context after usage

Hi fellow programmer I have a member class that returned IQueryable from a data context public static IQueryable<TB_Country> GetCountriesQ() { IQueryable<TB_Country> country; Bn_Master_DataDataContext db = new Bn_Master_DataDataContext(); country = db.TB_Countries .OrderBy(o => o.CountryNam...

Most efficient way to update with LINQ to SQL

Can I update my employee record as given in the function below or do I have to make a query of the employee collection first and then update the data? public int updateEmployee(App3_EMPLOYEE employee) { DBContextDataContext db = new DBContextDataContext(); db.App3_EMPLOYEEs.Attach(employee); db.SubmitChanges(); ...

Exceptions by DataContext

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 ...

Add the origin connectionString to Linq2Sql entities.

Hi, I have a ASP.NET web application that use the same DataContextType to access several Databases with the same schema. A problem I have is that I'd like to reference the origin Database of entities by adding to them a property (e.g. a ConnectionString property) and auto assign it on entity creation. I though it could be done easily...

WPF - 'Relational' Data in XAML Using DataContext

Hi, Say I have a list of Employee IDs from one data source and a separate data source with a list of Employees, with their ID, Surname, FirstName, etc. Is it possible in XAML only to get the Employee's name from the second data source and display it next to the ID, using something like this (with the syntax corrected)?.. <TextBlock x:...

DataContext Doesn't Exist in Dynamic Data Project?

This is really annoying...and I know it is something extremely simple... 1. I create a new Dynamic Data project. 2. I add a LINQ-to-SQL class and drag and drop some tables onto the class. 3. I open the global.asax.vb and uncomment the line: DefaultModel.RegisterContext(GetType(YourDataContext), New ContextConfiguration() With {.Scaffold...

Ninject and DataContext disposal

I'm using Ninject to retrieve my DataContext from the kernel and I was wondering if Ninject automatically disposes the DataContext, or how he handles the dispose() behaviour. From own experiences I know disposing the datacontext is pretty important and that whenever you create a direct object of the DataContext (as in: new DataContext())...

Should Linq to SQL repository implement IDisposable

I've been googling a ton on repository patterns with Linq over the last few days. There's a lot of info out there but it's often contradictory and I'm still looking for a definitive source. One of the things I'm still not sure about is whether the repository should instantiate it's own DataContext and have a SubmitChanges method, or if ...

Linq to SQL and Realtime Data

I have an application that needs to constantly (every 50ms), call to an MVC action, and pickup/drop off data. I am using Linq to SQL and MVC because of how simple they are to implement, and I know that they aren't perfect when it comes to performance, but it works relatively well, but the best speed I can get with my current approach is...

DataContext as Source for Converter Binding Within Resources

<Canvas.DataContext> <ViewModels:VMSomeControl Model="{Binding RelativeSource={RelativeSource TemplatedParent}}" /> </Canvas.DataContext> <!-- DataContext is not passed into these Instances. they also have no knowledge of their TemplatedParent. --> <Canvas.Resources> <!-- is there a way to use a binding t...

Variable Context Question

In the following code snippet, if I leave out the line of code that is surrounded by the /////'s, I get an error that reads: "Use of unassigned local variable CurrentDate". It seems a bit silly for me to just give CurrentDate an arbitrary value, is there a better way around this? DateTime CurrentDate; /////////////////////////// Curr...

Getting dates from observablecollection

Hi, I have a ObservableCollection bound to a Dockpanel. This collection holds some data, and one of the members is a datetime field. Now, i have created a calendar-control which requires a ObservableCollection of DateTime. Is it possible to get/make an ObservableCollection from the dockpanel? Let me show some xaml to make it a bit mor...

Help binding combobox within dataform to view model property outside dataform's context

I have two properties in my view model: //Relationship has property ReasonForEndingId private Relationship editRelationship; public Relationship EditRelationship { get { return editRelationship; } set { if (editRelationship != value) { ...

Binding DataTemplates (or another aproach)

Hi all, I'm having some troubles trying to dynamically generate content in WPF and after it bind data. I have the following scenario: TabControl - Dynamically generated TabItems through DataTemplate - inside TabItems, I have dynamic content generated by DataTemplate that I wish to bind (ListBox). The code follows: ::TabControl <Ta...

How to access the DataTemplate of a DataObject that has the DataTemplate with DataType assigned?

Hi guys, I have a DataObject and a DataTemplate that has the DataType=x:Type DataObject. I have a ContentControl which has as Content the DataObject. On OnContentChanged() of that ContentControl I need to access smtg from the DataTemplate of the new Conten which is a DataObject. How can I do this? Inverse, If I have a UIObject and ...

Should I return IEnumerable<T> or IQueryable<T> from my DAL?

I know this could be opinion, but I'm looking for best practices. As I understand, IQueryable implements IEnumerable, so in my DAL, I currently have method signatures like the following: IEnumerable<Product> GetProducts(); IEnumerable<Product> GetProductsByCategory(int cateogoryId); Product GetProduct(int productId); Should I be usin...

Listview of items from a object selected in another listview

Ok the title maybe a little confusing. I have a database with the table Companies wich has one-to-many relotionship with another table Divisions ( so each company can have many divisions ) and division will have many employees. I have a ListView of the companies. What I wan't is that when I choose a company from the ListView another Lis...

Linq2SQL InfoMessage

Hi, is it possible to access the InfoMessage event handler in a Linq2SQL data context? All of our code uses these messages to display useful information to the end user and since moving to Linq2SQL I cannot figure out how to show these messages. I have checked the connection object of the data context as well as the classes properties wi...

WPF Usercontrol interaction with parent view / viewmodel

Hi I have a mainView window which has its dataContext set to it's own viewModel. On that viewModel is a DateTime property which in turn is bound to a datepicker on my main view using 2 way binding. <toolkit:DatePicker DateSelected="{Binding mainDateTimeProperty, Mode=TwoWay}" /> This is all fine so far. On the change of my datetime p...