Search Results

Search found 783 results on 32 pages for 'datacontext'.

Page 17/32 | < Previous Page | 13 14 15 16 17 18 19 20 21 22 23 24  | Next Page >

  • Linq-to-SQL: how many datacontexts ?

    - by sh00
    I have a SQL Server 2008 database with 300 tables. The application I have to design is an Windows Forms app, .NET 3.5, C#. Which is the best way to work with Linq-to-SQL ? I intend to make a datacontext for each business entity. Is there any problem ? I need to know if this way of working with Linq-to-SQL has any disadvantage or can create performance issues ? Thanks.

    Read the article

  • LinQ: Add list to a list

    - by JohannesBoersma
    I have the following code: var columnNames = (from autoExport in dataContext.AutoExports where autoExport.AutoExportTemplate != null && ContainsColumn(autoExport.AutoExportTemplate, realName) select GetDbColumnNames(autoExport.AutoExportTemplate, realName)).ToList(); Where the function GetDbColumns() returns an List<string>. So columNames is of the type List<List<string>>. Is it possible to create a List<string>, so each element of the list of GetDbColumns is added to the result of the LinQ query?

    Read the article

  • SQL Compact - Hang on invalid file

    - by eWolf
    I use Linq to Sql Compact with code generated by sqlmetal. When I open an invalid database, like eg an mp3, I can create the DataContext without getting an Exception. But when I query any data or call DatabaseExists, the application hangs. Why is no exception thrown? Is this a known problem?

    Read the article

  • How to bind the Command property of the ItemTemplate CheckBox to ViewModel object's property?

    - by 123Developer
    Let me ask this question with a pseudo code: Where "Contacts" the ViewModel object set as the DataContext for the window. "Contacts" has "PersonCollection" , public ICommand PersonSelectedCommand properties. "PersonCollection" is List "Person" has Name, Age properties Currently this is not working as CheckBox is trying to find and bind the ICommand "PersonSelectedCommand" property of object "person", which does not exists! How will bind the CheckBox to the ICommand "PersonSelectedCommand" property of object "Contact" Thanks and regards 123Deveopler

    Read the article

  • LINQ2SQL: how many datacontexts ?

    - by sh00
    I have a SQL Server 2008 database with 300 tables. The application I have to design is an Windows Forms app, .NET 3.5, C#. Which is the best way to work with LINQ2SQL ? I intend to make a datacontext for each business entity. Is there any problem ? I need to know if this way of working with LINQ has any disadvantage or can create performance issues ? Thanks.

    Read the article

  • Is there an automatic way to generate a rollback script when inserting data with LINQ2SQL?

    - by Jedidja
    Let's assume we have a bunch of LINQ2SQL InsertOnSubmit statements against a given DataContext. If the SubmitChanges call is successful, is there any way to automatically generate a list of SQL commands (or even LINQ2SQL statements) that would automatically undo everything that was submitted? It's like executing a rollback even though everything worked as expected. Note: The destination database will either be Oracle or SQL Server, so if there is specific functionality for both databases that will achieve this, I'm happy to use that as well.

    Read the article

  • ASP.NET LINQ to SQL SubmitChanges() doesn't update the database

    - by Alex
    In my 2nd ASP.NET MVC project I'm facing a very weird problem: when I call the SubmitChanges method of the DataContext class, nothing updates in the database. It's weird because everything works fine with my first project. I'm using a remote database created in Sql Server Management Studio, I tried doing some queries there and in Visual Studio 2010 (where I have the connection to the database), they all work. Where might the problem be hidden?

    Read the article

  • WPF MVVM Cancel Edit

    - by terkri
    How can I implement cancelation of editing an object using MVVM. For example: I have a list of customers. I choose one customer an click the button "Edit", a dialog window(DataContext is binded to CustomerViewModel) opens and I start editing customer's fields. And then I decide to cancel editing, but the fields of the customer have been already changed, so how can I return a customer to its previous state in MVVM?

    Read the article

  • WPF multibound textblock not updating

    - by Superstringcheese
    I want to create a program which calculates how long it will take to repeat a process a certain number of times. I've scaled this down a lot for this example. So, I have some textboxes which are bound to properties in a class: Count: <TextBox x:Name="txtCount" Text="{Binding Count, Mode=TwoWay}" Width="50"/> Days: <TextBox x:Name="txtDays" Text="{Binding Days, Mode=TwoWay}" Width="50"/> and a textblock which is multibound like so: <TextBlock x:Name="tbkTotal"> <TextBlock.Text> <MultiBinding StringFormat="Days: {0}, Count: {1}"> <Binding Path="Days" /> /* This isn't updating */ <Binding Path="Count" /> </MultiBinding> </TextBlock.Text> </TextBlock> My DataContext is set in the Window1.xaml.cs file. public Window1() { InitializeComponent(); Sample sample = new Sample(); this.DataContext = sample; } I can update the multibound textblock with the Count property just fine, but the Days property always shows 0, even though the Days input accurately reflects changes. I believe that this is because my accessors are different for Days - namely, the Set method. This class is in a different file. public class Sample : INotifyPropertyChanged { private int _count; private TimeSpan _span; public int Count { get { return _count; } set { _count = value; NotifyPropertyChanged("Count"); /* Doesn't seem to be needed, actually */ } } public TimeSpan Span { get { return _span; } } /* The idea is to provide a property for Days, Hours, Minutes, etc. as conveniences to the inputter */ public double Days { get { return _span.Days; } set { TimeSpan ts = new TimeSpan(); double val = value > 0 ? value : 0; ts = TimeSpan.FromDays(val); _span.Add(ts); NotifyPropertyChanged("Span"); /* Here I can only get it to work if I notify that Span has changed - doesn't seem to be aware that the value behind Days has changed. */ } } private void NotifyPropertyChanged(string property) { if (null != this.PropertyChanged) { PropertyChanged(this, new PropertyChangedEventArgs(property)); } } public Sample() { _count = 0; _span = new TimeSpan(); } public event PropertyChangedEventHandler PropertyChanged; }

    Read the article

  • Force Binding Update Silverlight

    - by Matt
    How can I force my objects DataContext bindings to update? I'm using an event on a grid, and binding updates are not being processed before my event fires. Any cheap tricks to get around this? In the end I can always do things the old manual way of getting the values from my textboxes and updating my object, but it'd be nice to have binding do it for me.

    Read the article

  • T-SQL generated from LINQ to SQL is missing a where clause

    - by Jimmy W
    I have extended some functionality to a DataContext object (called "CodeLookupAccessDataContext") such that the object exposes some methods to return results of LINQ to SQL queries. Here are the methods I have defined: public List<CompositeSIDMap> lookupCompositeSIDMap(int regionId, int marketId) { var sidGroupId = CompositeSIDGroupMaps.Where(x => x.RegionID.Equals(regionId) && x.MarketID.Equals(marketId)) .Select(x => x.CompositeSIDGroup); IEnumerator<int> sidGroupIdEnum = sidGroupId.GetEnumerator(); if (sidGroupIdEnum.MoveNext()) return lookupCodeInfo<CompositeSIDMap, CompositeSIDMap>(x => x.CompositeSIDGroup.Equals(sidGroupIdEnum.Current), x => x); else return null; } private List<TResult> lookupCodeInfo<T, TResult>(Func<T, bool> compLambda, Func<T, TResult> selectLambda) where T : class { System.Data.Linq.Table<T> dataTable = this.GetTable<T>(); var codeQueryResult = dataTable.Where(compLambda) .Select(selectLambda); List<TResult> codeList = new List<TResult>(); foreach (TResult row in codeQueryResult) codeList.Add(row); return codeList; } CompositeSIDGroupMap and CompositeSIDMap are both tables in our database that are represented as objects in my DataContext object. I wrote the following code to call these methods and display the T-SQL generated after calling these methods: using (CodeLookupAccessDataContext codeLookup = new CodeLookupAccessDataContext()) { codeLookup.Log = Console.Out; List<CompositeSIDMap> compList = codeLookup.lookupCompositeSIDMap(5, 3); } I got the following results in my log after invoking this code: SELECT [t0].[CompositeSIDGroup] FROM [dbo].[CompositeSIDGroupMap] AS [t0] WHERE ([t0].[RegionID] = @p0) AND ([t0].[MarketID] = @p1) -- @p0: Input Int (Size = 0; Prec = 0; Scale = 0) [5] -- @p1: Input Int (Size = 0; Prec = 0; Scale = 0) [3] -- Context: SqlProvider(Sql2005) Model: AttributedMetaModel Build: 3.5.30729.1 SELECT [t0].[PK_CSM], [t0].[CompositeSIDGroup], [t0].[InputSID], [t0].[TargetSID], [t0].[StartOffset], [t0].[EndOffset], [t0].[Scale] FROM [dbo].[CompositeSIDMap] AS [t0] -- Context: SqlProvider(Sql2005) Model: AttributedMetaModel Build: 3.5.30729.1 The first T-SQL statement contains a where clause as specified and returns one column as expected. However, the second statement is missing a where clause and returns all columns, even though I did specify which rows I wanted to view and which columns were of interest. Why is the second T-SQL statement generated the way it is, and what should I do to ensure that I filter out the data according to specifications via the T-SQL? Also note that I would prefer to keep lookupCodeInfo() and especially am interested in keeping it enabled to accept lambda functions for specifying which rows/columns to return.

    Read the article

  • WPF DataGrid, Help with Binding to a List<X> where each X has a Dictionary<Y,object> property.

    - by panamack
    I'm building an application which helps someone manage an event and works with data originating from Excel. I want to use the WPF Toolkit DataGrid to display the incoming data but can't guarantee how many Columns there are going to be or what information they will contain. I'd like to have an Info class that stores column information and have each Visitor at my Event own a Dictionary that uses shared references to Info objects for the keys. Here's the general gist: public class Info{ public string Name{get;set;} public int InfoType{get;set;} } public class Visitor{ public Dictionary<Info,object> VisitorInfo {get;set;} } public class Event{ public List<Visitor> Visitors{get;set;} public Event(){ Info i1 = new Info(){ Name = "ID", InfoType = 0};// type 0 for an id Info i2 = new Info(){ Name = "Name", InfoType = 1};// type 1 for a string Info i3 = new Info(){ Name = "City", InfoType = 1}; Visitor v1 = new Visitor(); v1.VisitorInfo.Add(i1, 0); v1.VisitorInfo.Add(i2, "Foo Harris"); v1.VisitorInfo.Add(i3, "Barsville"); Visitor v2 = new Visitor(); ... this.Visitors.Add(v1); this.Visitors.Add(v2); ... } } XAML: <!-- Window1.xaml --> ... <local:Event x:Key="MyEvent"/> ... <wpftk:DataGrid DataContext="{StaticResource MyEvent}" ItemsSource="{Binding Path=Visitors}" /> Disappointingly, DataGrid just sees a collection of Visitors each having a VisitorInfo property and displays one column called VisitorInfo with the string "(Collection)" once for each Visitor. As a workaround I've created a ListTVisitorToDataTableConverter that maps Infos to DataColumns and Visitors to DataRows and used it like this: <wpftk:DataGrid DataContext="{StaticResource Event}" ItemsSource{Binding Path=Visitors, Converter={StaticResource MySmellyListTVisitorToDataTableConverter}}" /> I don't think this is good though, I haven't started trying to convert back yet which I guess I'll need to do if I want to be able to edit any data! How can I do better? Thanks.

    Read the article

  • How do i bind my ObservableCollection<T> object in my codebehind to my listbox... Silverlight WP7

    - by Nawaz Dhandala
    This is My codebehind public System.Collections.ObjectModel.ObservableCollection FriendList { get; set; } // I want to bind this to my listbox public Friends() //this is constructor { InitializeComponent(); this.DataContext = this; //I think this is what I'm doing is right....:) } How do I bind my FriendList to the ListBox - FriendList has a property of user.UserName which I want to display it in the TextBlock "friendUsername" Please help!!! Thanks for your answers!!!

    Read the article

  • Repository Pattern: SaveOrUpdate() in Entity Framework and L2S

    - by JMSA
    These web articles uses separate Save() and Update() methods in the repository pattern. I am using repository pattern. How can I write a SaveOrUpdate() method in Entity Framework with the help of ObjectContext and in Linq-To-SQL with the help of DataContext? That is, how can I write a single method that shall do both save and update job?

    Read the article

  • Why doesn't TextBlock databinding call ToString() on a property whose compile-time type is an interf

    - by Jay
    This started with weird behaviour that I thought was tied to my implementation of ToString(), and I asked this question: http://stackoverflow.com/questions/2916068/why-wont-wpf-databindings-show-text-when-tostring-has-a-collaborating-object It turns out to have nothing to do with collaborators and is reproducible. When I bind Label.Content to a property of the DataContext that is declared as an interface type, ToString() is called on the runtime object and the label displays the result. When I bind TextBlock.Text to the same property, ToString() is never called and nothing is displayed. But, if I change the declared property to a concrete implementation of the interface, it works as expected. Is this somehow by design? If so, any idea why? To reproduce: Create a new WPF Application (.NET 3.5 SP1) Add the following classes: public interface IFoo { string foo_part1 { get; set; } string foo_part2 { get; set; } } public class Foo : IFoo { public string foo_part1 { get; set; } public string foo_part2 { get; set; } public override string ToString() { return foo_part1 + " - " + foo_part2; } } public class Bar { public IFoo foo { get { return new Foo {foo_part1 = "first", foo_part2 = "second"}; } } } Set the XAML of Window1 to: <Window x:Class="WpfApplication1.Window1" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" Title="Window1" Height="300" Width="300"> <StackPanel> <Label Content="{Binding foo, Mode=Default}"/> <TextBlock Text="{Binding foo, Mode=Default}"/> </StackPanel> </Window> in Window1.xaml.cs: public partial class Window1 : Window { public Window1() { InitializeComponent(); DataContext = new Bar(); } } When you run this application, you'll see the text only once (at the top, in the label). If you change the type of foo property on Bar class to Foo (instead of IFoo) and run the application again, you'll see the text in both controls.

    Read the article

  • WP7 databinding displays int but not string?

    - by user1794106
    Whenever I test my app.. it binds the data from Note class and displays it if it isn't a string. But for the string variables it wont bind. What am I doing wrong? Inside my main: <Grid x:Name="ContentPanel" Grid.Row="1" Margin="12,0,12,0"> <ListBox x:Name="Listbox" SelectionChanged="listbox_SelectionChanged" ItemsSource="{Binding}"> <ListBox.ItemTemplate> <DataTemplate> <Border Width="800" MinHeight="60"> <StackPanel> <TextBlock x:Name="Title" VerticalAlignment="Center" FontSize="{Binding TextSize}" Text="{Binding Name}"/> <TextBlock x:Name="Date" VerticalAlignment="Center" FontSize="{Binding TextSize}" Text="{Binding Modified}"/> </StackPanel> </Border> </DataTemplate> </ListBox.ItemTemplate> </ListBox> </Grid> </Grid> in code behind: protected override void OnNavigatedTo(System.Windows.Navigation.NavigationEventArgs e) { MessageBox.Show("enters onNav Main"); DataContext = null; DataContext = Settings.NotesList; Settings.CurrentNoteIndex = -1; Listbox.SelectedIndex = -1; if (Settings.NotesList != null) { if (Settings.NotesList.Count == 0) { Notes.Text = "No Notes"; } else { Notes.Text = ""; } } } and public static class Settings { public static ObservableCollection<Note> NotesList; static IsolatedStorageSettings settings; private static int currentNoteIndex; static Settings() { NotesList = new ObservableCollection<Note>(); settings = IsolatedStorageSettings.ApplicationSettings; MessageBox.Show("enters constructor settings"); } notes class: public class Note { public DateTimeOffset Modified { get; set; } public string Title { get; set; } public string Content { get; set; } public int TextSize { get; set; } public Note() { MessageBox.Show("enters Note Constructor"); Modified = DateTimeOffset.Now; Title = "test"; Content = "test"; TextSize = 32; } }

    Read the article

  • Object relationships

    - by Hammerstein
    This stems from a recent couple of posts I've made on events and memory management in general. I'm making a new question as I don't think the software I'm using has anything to do with the overall problem and I'm trying to understand a little more about how to properly manage things. This is ASP.NET. I've been trying to understand the needs for Dispose/Finalize over the past few days and believe that I've got to a stage where I'm pretty happy with when I should/shouldn't implement the Dispose/Finalize. 'If I have members that implement IDisposable, put explicit calls to their dispose in my dispose method' seems to be my understanding. So, now I'm thinking maybe my understanding of object lifetimes and what holds on to what is just wrong! Rather than come up with some sample code that I think will illustrate my point, I'm going to describe as best I can actual code and see if someone can talk me through it. So, I have a repository class, in it I have a DataContext that I create when the repository is created. I implement IDisposable, and when my calling object is done, I call Dispose on my repository and explicitly call DataContext.Dispose( ). Now, one of the methods of this class creates and returns a list of objects that's handed back to my front end. Front End - Controller - Repository - Controller - Front End. (Using Redgate Memory Profiler, I take a snapshot of my software when the page is first loaded). My front end creates a controller object on page load and then makes a request to the repository sending back a list of items. When the page is finished loading, I call Dispose on the controller which in turn calls dispose on the context. In my mind, that should mean that my connection is closed and that I have no instances of my controller class. If I then refresh the page, it jumps to two 'Live' instances of the controller class. If I look at the object retention graph, the objects I created in my call to the list are being held onto ultimately by what looks like Linq. The controller/repository aside, if I create a list of objects somewhere, or I create an object and return it somewhere, am I safe to just assume that .NET will eventually come and clean things up for me or is there a best practice? The 'Live' instances suggest to me that these are still in memory and active objects, the fact that RMP apparently forces GC doesn't mean anything?

    Read the article

  • Linq2SQL or EntityFramework and databinding

    - by rene marxis
    is there some way to do databinding with linq2SQL or EntityFramework using "typed links" to the bound property? Public Class Form1 Dim db As New MESDBEntities 'datacontext/ObjectContext Dim bs As New BindingSource Private Sub Form1_Load(sender As System.Object, e As System.EventArgs) Handles MyBase.Load bs.DataSource = (From m In db.PROB_GROUP Select m) grid.DataSource = bs TextBox1.DataBindings.Add("Text", bs, "PGR_NAME") TextBox1.DataBindings.Add("Text", bs, db.PROB_GROUP) '**<--- Somthing like this** End Sub End Class I'd like to have type checking when compiling and the model changed.

    Read the article

  • Assign enum property in xaml using silverlight

    - by Malcolm
    I have a property of datattype enum : like public BreakLevel Level { get { return level; } set { level = value; } } And enum defined : public enum BreakLevel { Warning, Fatal } I want bind the neum property to the visibility of my border , somewhat like this: Visibility="{Binding BreakLevel.Fatal}" so is it possible? <Border CornerRadius="4" BorderThickness="1" BorderBrush="#DAE0E5" Visibility="{Binding DataContext.IsError, Converter={StaticResource BoolToVisibilityConverter}, RelativeSource={RelativeSource TemplatedParent}}" >

    Read the article

  • How to refresh xmlDataProvider when xml document changes at runtime in WPF?

    - by Kajsa
    I am trying to make a image viewer/album creator in visual studio, wpf. The image paths for each album is stored in an xml document which i bind to to show the images from each album in a listbox. The problem is when i add a image or an album at runtime and write it to the xml document. I can't seem to make the bindings to the xml document update so they show the new images and albums aswell. Calling Refresh() on the XmlDataProvider doesn't change anything. I don't wish to redo the binding of the XmlDataProvider, just make it read from the same source again. XAML: ... <Grid.DataContext> <XmlDataProvider x:Name="Images" Source="Data/images.xml" XPath="/albums/album[@name='no album']/image" /> </Grid.DataContext> ... <Label Grid.Row="1" Grid.Column="0" HorizontalAlignment="Right" VerticalAlignment="Bottom" Padding="0" Margin="0,0,0,5" Content="{x:Static resx:Resource.AddImageLabel}"/> <TextBox Grid.Row="1" Grid.Column="1" HorizontalAlignment="Stretch" VerticalAlignment="Bottom" Name="newImagePath" Margin="0" /> <Button Grid.Row="1" Grid.Column="2" HorizontalAlignment="Left" VerticalAlignment="Bottom" Name="newImagePathButton" Content="{x:Static resx:Resource.BrowseImageButton}" Click="newImagePathButton_Click" /> ... <ListBox Grid.Column="0" Grid.ColumnSpan="4" Grid.Row="3" HorizontalAlignment="Stretch" Name="thumbnailList" VerticalAlignment="Bottom" IsSynchronizedWithCurrentItem="True" ItemsSource="{Binding BindingGroupName=Images}" SelectedIndex="0" Background="#FFE0E0E0" Height="110"> ... Code behind: private void newImagePathButton_Click(object sender, RoutedEventArgs e) { string imagePath = newImagePath.Text; albumCreator.addImage(imagePath, null); //Reset import image elements to default newImagePath.Text = ""; //Refresh thumbnail listbox Images.Refresh(); Console.WriteLine("Image added!"); } public void addImage(string source, XmlElement parent) { if (parent == null) { //Use default album parent = (XmlElement)root.FirstChild; } //Create image element with source element within XmlElement newImage = xmlDoc.CreateElement(null, "image", null); XmlElement newSource = xmlDoc.CreateElement(null, "source", null); newSource.InnerText = source; newImage.AppendChild(newSource); //Add image element to parent parent.AppendChild(newImage); xmlDoc.Save(xmlFile); } Thank you very much for any help!

    Read the article

  • How to bind Listbox to two properties?

    - by Gabriel
    I have in Silverlight a Grid with DataContext set to class ViewModel. ViewModel contains list of items (each of them containing int ID and string Text) and an integer "ID", which identifies actually active item (not selected item). I would like to construct xaml with ListBox where activated item has another color. How can I do it?

    Read the article

< Previous Page | 13 14 15 16 17 18 19 20 21 22 23 24  | Next Page >