linq-to-sql

How to add LINQ to SQL query results to Observable Collection?

In WPF app I have an Observable Collection which is connected through databinding with ListView. I would like to populate this Observable Collection from LINQ to SQL query, but with no success. In fact my code even doesn't compile (I pointed out the problem lines with comments). The structure of underlying Observable Collection Class i...

How to use PropertyChangedEventHandler of LINQ to SQL class for immediate updating?

In my WPF app I have implemented LINQ to SQL query which populates an Observable Collection connected with ListView. It is in this method which I can call from somwhere and it works OK: private void VisualizeAllShows() { MyfirstdbDataContext context = new MyfirstdbDataContext(); _ShowQuCollection.Clear(); var sh = from p i...

Need solution for troubled null problem...

For a day now i'm stuck with this null problem in my repository. here is my piece of code writen for linq to sql... i've tried a lot of options but no help for this. the problem here is if the vidList got null value, it got stuck right in 3rd line. if the vidList is ok, but the fidListE got null, it will stil cause null exception in t...

Why do I get "error: ... must be a reference type" in my C# generic method?

In various database tables I have both a property and a value column. I'm using Linq to SQL to access the database. I'm writing a method which returns a dictionary containing the properties/values retrieved from the given database table: private static Dictionary<string, string> GetProperties<T>(Table<T> table) { Dictionary<string,...

DateTime region specific formatting in WPF ListView

In WPF app I have a ListView: <ListView Height="100" Width="434" Margin="0,2,0,0" x:Name="lvItems" ItemsSource="{Binding ElementName=MainWindow, Path=ShowQuCollection}" > <ListView.View> <GridView> <GridViewColumn Header="Date" Width="100" DisplayMemberBinding="{Binding Date}"/> <GridViewColumn Header="Time" Width="100" ...

UPDATE SELECT in LINQ to SQL

I am writing a multithreaded service that picks up jobs to process that has the status of 1 (unprocessed). As soon as they are picked up, I need to change the status of those rows to 2 (indicates In Progress) so that another thread (that is spawned within a few seconds) does not pick up these rows for processing. For select, I would do ...

Are Visual Studio pre-build events guaranteed to finish before compiling starts?

I'm using a pre-build event in Visual Studio to run a batch (.bat) file that performs some code generation (specifically, I'm running SqlMetal.exe to generate LinqToSql code). Is the batch file guaranteed to finish before the compilation begins? Or does it run the batch asynchronously? Bottom line: I want to make sure the new code gets...

Using textbox value as parameter in LINQ dat source/gridview : A value of type 'String' cannot be converted to type 'Double'

Hello all - it's a New Year but you're still left with a thick Mr Dean!! Ok, the scenario - I have a textbox, a two radio buttons, a button and a gridview. <code> <body> <form id="form1" name="form1" runat="server"> <asp:TextBox ID="tbxHowMany" runat="server" style="z-index: 1; left: 245px; top: 105px; position: absolute; hei...

Getting mapped rows from IQueryable<ForeignKey> in Linq2Sql

The situation is: a webpage displays a listing of Gatherings to a logged-in user. Among this Queryable group might be Gatherings that the user is subscribed to but has not yet viewed until loading this page. Now that the Gatherings have been viewed by this user, I want to mark them as such. I can get this to work by using ToList() and C...

How should I integrate SqlTransaction legacy code with TranactionScope?

I have an existing application that uses a lot of SqlTranaction calls. The way the application is built we get a bunch of code that looks a bit like this (error handling etc removed for brevity): Using transaction As SqlTransaction = Database.CreateSqlTransaction() If Not Me.FitnessSession.FitnessTestSessionID.HasValue Then ...

WPF custom control objects databinding to List(T) based on query

In a window of my WPF application I have several hundreds of objects, they based on a custom control. They differ from each other only by name: ... <MyNamespace:MyCustControl x:Name="x4y3" /> <MyNamespace:MyCustControl x:Name="x4y4" /> <MyNamespace:MyCustControl x:Name="x4y5" /> <MyNamespace:MyCustControl x:Name="x4y6" /> <MyNamespace:M...

Count occurrences of values across multiple columns

I am having a terrible time finding a solution to what I am sure is a simple problem. I started an app with data in Lists of objects. It's pertinent objects used to look like this (very simplified): class A { int[] Nums; } and List<A> myListOfA; I wanted to count occurrences of values in the member array over all the List....

SqlMetal Not Generating Views, Functions, or Stored Procedures

I am using the following commands as part of a cmd file: sqlmetal /server:localhost\SQLEXPRESS /database:DashBoard /dbml:DataClasses.dbml /namespace:DashBoard.Data sqlmetal /server:localhost\SQLEXPRESS /database:DashBoard /views /functions /sprocs /code:DataClasses.designer.cs /context:DataClassesDataContext /namespace:DashBoard.Data Da...

LINQ to SQL : Why can't I have a Zero to Many Cardinality

I created a foreign key relationship in my database so that I could access another table as a property in this case House.Area Now if I create a House object and have Area as null I get the following exception on SubmitChanges(): An attempt was made to remove a relationship between a Area and a House. However, one of the relationshi...

How can I shorten this linq to sql query?

Hi I am am making a calendar and to make it easier on myself I break up appointments that span over multiple weeks. For instance Jan 1st to Jan 31st spans like 6 weeks(my calendar is always 42 cells - 6 by 7). So I would basically have 6 rows stored in my database. However somethings I do require to me to put all these rows back toget...

Using 'Auto-Sync' feature of DBML with SQLite

I'm having trouble trying to use the 'Auto-Sync' feature of DBML with SQLite. I have a class in my data model that contains a primary key (id). This key is defined as "INTEGER PRIMARY KEY", which SQLite maps to the rowid of the row. To support this, I have set "Auto Generated Value" to 'True' and "Auto-Sync" to 'OnInsert'. The proble...

Help with linq2sql generic lambda expression

In my Database almost every table has its own translations table. I.e. Sports has SportsTranslations table with columns: SportId, LanguageId, Name. At the moment I'm taking translations like: int[] defaultLanguages = { 1, 3 }; var query = from s in dc.Sports select new { sportName = s...

Is there any reason to use one DataContext instance, instead of several?

For example, I have 2 methods that use one DataContext (Linq to sql). using(DataContext data = new DataContext){ // doing something another_datamethod(data); } void another_datamethod(DataContext data){ // doing } Use this style? Or with the same result, I can create separate "using DataContext". What benefits, I would a...

DataContext pre-populated with some pretty constanst tables

Is this possible to populate some constant small tables as cache for DataContext without using database? For example, I have 10 Roles rows, and wonna quick (without database hit) access to them when doing big select? ...

Linq to SQL provides different results when using TOP and Between

Hi, I'm using Linq to Sql (in fact it's Dynamic Linq to SQL that allows you to pass strings at runtime for where clauses, orderby etc.) But I'm getting some different results and it seems to be based on whether the underlying T-SQL is using the TOP keyword or using BETWEEN. I've tried to the break the problem down into a small example,...