linq-to-sql

ASP.NET MVC2 UpdateModel not updating a public property included in whitelist

I have a class Foo with a field UpdateMe of type Confirmation as described below.. public class Foo { public Confirmation UpdateMe{get;set;} public int BarInt{get;set} } public enum Confirmation { N = 0, Y = 1 } I have a whitelist that has UpdateMe, and runs the following way... [AcceptVerbs(HttpVerbs.Post), ValidateAntiForg...

DBML customization vs regeneration

I'm having a database with a lot of foreign key relationships defined. When I simply drag any table involved in these FK connections into the DBML editor, so as to machine-generate the DBML file, these will all be represented as associations. From here I'm able to make any changes to these associations: I might want the parent end of th...

How to compare date with milliseconds with LINQ

I try to make a query to my database with LINQ to SQL. example : var t = from a in context.A where a.date == myDate select a; The problem is the date from SQL was return with millisecond, myDate variable contain de good milliseconds, but when i compare the date together the comparaison is not valide because the default output of myDa...

ViewModel validation object issue with L2SQL generated model class

Hi guys, i'm having issues with implementing a ViewModel class which acts as a wrapper class around a Model class called "User" generated by L2SQL. In short, I have two instances when i have to validate against the L2SQL model. One when the user first signs up, and the second when the user logs in and edits only part of his account data....

WPF - Correct way to commit changes when using ObservableCollection and linq-2-sql

If all of my wpf controls bind to ObservableCollections and I am using linq-2-sql to populate these collections, what is the correct way to commit changes whenever properties of these objects are updated? Currently I am calling DataClassesDataContext.SubmitChanges() manually, which is a bit tedious. Is there a way to do this automatical...

Bulk inserts and duplicate records with LINQ to SQL

Is there a "best practice" way of handling bulk inserts (via LINQ) but discard records that may already be in the table? Or I am going to have to either do a bulk insert into an import table then delete duplicates, or insert one record at a time? 08/26/2010 - EDIT #1: I am looking at the Intersect and Except methods right now. I am ...

Find parent based on children properties linq to sql

Lets say we have a sql relationship that can be modeled like this using C# classes public class Parent { public int ID { get; set; } public List<Child> Children { get; set; } } public class Child { public int ID { get; set; } public Parent Parent { get; set; } public int Number { get; set; } } I also know that th...

In Memory Data Cache for Performance in .Net Applications

Hey All - We have an application (rules engine) that has a lot of tables in memory to perform certain business rules. This engine is also used for writing back to the database when needed. The DB structure is denormalized, and we have 5 transactional tables, that also sometimes need to be queried for reporting. The issue here is, we w...

LINQ query using join and aggregate functions

Urgh...my LINQ has suddenly taken a turn for the worse!! I have two tables and want to join and perform aggregate functions upon the tables. Firstly, is this possible, I am assuming it is, and secondly, how do I handle the aggregate functions? As part of the same LINQ statement? The SQL statement will look a bit like this: SELECT ...

LinQ to SQL adding delimited data but checking for duplicates

I have a table of Contacts, and a table of Groups which has a many-to-many relationship managed by a simple contacts_groups table: contacts_groupsID Identity INT ContactID INT GroupID INT I have a delimted String of contact IDs e.g. "1|23|987|2346|33|9821|" which I need to insert into the contacts_groups table (along with the groupID)....

Help needed on SQL query to Linq Conversion

Please help me write LINQ for this SQL select svc.SvcName, svcOptions.SvcOptionName, svcMap.Price from svcMap inner join svc on svcMap.SvcId = svc.SvcId inner join svcOptions on svcOptions.SvcOptionId = CASE WHEN (svcMap.DesiredSvcOptionId <> 0 AND svcMap.DesiredSvcOptionId <> svc.DisabledSvcOptionId) THEN ...

Flexiable update in Linq To Sql

Using Linq To Sql/Entities we have enough flexibility to write select queries But what about update queries. What if i need to do something simple like that: UPDATE suppliers SET supplier_name = (SELECT customers.name FROM customers WHERE customers.customer_id = suppliers.supplier_id) Using Linq to Sql i need to run a lot o...

what are the pros and cons using LINQ to SQL ?

performance ? architecture ? the system in question will always be a MS SQL database there is an existing DAL but there will be refactoring done on the system and Linq-to-SQL seems a good candidate to avoid maintaining a DAL or SP's ...

late binding in linq

I have a simple LINQ query that is going against a collection. Dim oList = From w In Os Order By w.ClassTitle Descending Select w What I'd like to be able to do though is pass into this whether it's descending or ascending. I'm not sure how to do that. Also, if I were to have a where clause in here.. sa...

Transaction for sequential numbering in LINQ to SQL.

I have a scenario where just before I insert a JobCard record, I need to generate an ID number (not the identity column PK), that is an increment of the last ID number in the DB. How do I wrap this in a transaction in LINQ to SQL so that no other JobCard record can be inserted between the time I select the last ID number and insert my J...

How do I avoid timeouts with SqlServer full text search?

We're using SqlServer 2008. In SSMS, queries on the full text catalog might take 2-5 seconds the first time, but after that, return quite quickly. On the other hand, running a query from via Linq2Sql will timeout. Here's what we have: The SQL Inline Table UDF CREATE FUNCTION dbo.SearchArchiveFTS ( @query nvarchar(255) ) RETURN...

Linq To Sql / SQL Query Help

I have a table that looks like this: Id PageId Key Content LastUpdated --------------------------------------------- 1 12 key1 content1 02-21-2010 2 12 key1 content2 02-25-2010 3 12 key2 content1 02-21-2010 4 12 key2 content2 02-25-2010 5 12 key3 ...

How to use distinct with group by in Linq to SQL

I'm trying to convert the following sql to Linq 2 SQL: select groupId, count(distinct(userId)) from processroundissueinstance group by groupId Here is my code: var q = from i in ProcessRoundIssueInstance group i by i.GroupID into g select new { Key = g.Key, Count = g.Select(x => x.UserID).Distinct().Count...

LINQ Query with dynamic number of boolean ANDs

I am working on a search web page for my site. The requirements state that users can enter text for any combination of 9+ fields and the search should do an 'AND' match when querying the database. I could fairly quickly write this as a stored procedure using 'ISNULL' but I'm trying to figure out how to accomplish the same thing in LINQ...

stored procedure returns varchar in LINQ

I would like to know if in SQL is it possible to return a varchar value from a stored procedure, most of the examples I have seen the return value is an int Example within a proc declare @ErrorMessage varchar(255) if @TestFlag = 0 set @ErrorMessage = 'Test' return @ErrorMessage calling on asp.net Updated: Error: Conversion fai...