linq

Advanced multiple join in subquery using LINQ

I have spent the afternoon trying to wrap my mind around how to translate the following query into LINQ, but I can't quite get there. declare @productId int; set @productId = 3212; select * from InformationData data where productId = @productId and orgId = 1 and exists( select id from ( select coalesce(id1.id, id2.id, id3.id)...

Concurrency with Linq To Sql Stored Procedures

I come from the asp.net world where we'd use an objectdatasource, hooked up to data access layer, and set it's ConflictDetection property to "CompareAllValues". There is an OldValuesParameterFormatString on the ObjectDataSource that you use to identify old value parameters. The sql procedure that does an update would then require both n...

Linq query with Array in where clause?

Hello all, I have searched for this, but still can't seem to get this to work for me. I have an array of Id's associated with a user (their Organization Id). These are placed in an int[] as follows: int[] OrgIds = (from oh in this.Database.OrganizationsHierarchies join o in this.Database.Organizations on oh.Org...

Seralize System.Data.Linq.SqlClient.SqlProvider+SingleResult - C#, WCF,VS2008

This is my sample code var returnResult = datacontext.Searchresult('1'); returnResult is of System.Data.Linq.SqlClient.SqlProvider.SingleResult Trying to serialize it using DataContractSerializer results in error below. {"Type 'System.Data.Linq.SqlClient.SqlProvider+SingleResult`1[Service.SearchResult]' cannot be serialized. Conside...

Should my DAL return DataTables or I...whatever<>?

EDIT 1 I apologize but after reading the 2 suggested articles I still don't understand what I should use. I understand that using IQueryable is not preferred for various reasons but does that eliminate IEnumerable as well? Is a DataTable really my best option? In short, I guess, what is the preferred Return type? I have the followi...

IMultipleResults: how do I deal with multiple result sets from a stored proc when they don't map to types?

This post on SO answers most of the questions I have (much thanks to Pure.Krome for the thorough response) about how to build a query that returns multiple results. However, in the case that I'm working with my tables that are coming back are sort of dependent on how the proc behaves. Can't change the proc. The results that are coming ba...

LINQ to Entities Entity Initialization

In the tutorials for ASP.Net MVC, the LINQ to Entities code looks like: public class MyController : Controller { private Models db; public ActionResult Index() { db = new Models(); var foo = (from f in db.foo select f).ToList(); return View(foo); } } I'm guessing this has something to do with t...

First was RDO, later ADO and more later ADO.NET, now LINQ. ¿Is LINQ the next standard or I should wait?

In my humble opinion, Microsoft is changing rules about database managing each four or five years. I remember old days when RDO was the solution to connect to SQL server. I refresh my knowledge to use ADO because RDO was obsolete. ADO was very good and effective, but not so long ago, I found myself programming and refreshing again my kno...

linq match word with boundaries

say i have a nvarchar field in my database that looks like this 1, "abc abccc dabc" 2, "abccc dabc" 3, "abccc abc dabc" i need a select LINQ query that would match the word "abc" with boundaries not part of a string in this case only row 1 and 3 would match ...

Linq and the Equality Operator: Expression of type 'System.Int32' cannot be used for parameter of type 'System.Object'

I'm trying to override the equality (==) operator in C# to handle comparing any type to a custom type (the custom type is really a wrapper/box around null). So I have this: internal sealed class Nothing { public override bool Equals(object obj) { if (obj == null || obj is Nothing) return true; else return false; } public...

Static methods vs repository pattern with Linq2Sql

I've hit on the idea of creating static methods on the partial Linq queries such as public partial class User { public static User FindByGuid(string guid, ApplicationDataContext context) { return context.Users.Where(x => x.GUID == guid).Single(); } } So, for example, I can easily find a user by doing: using (var c...

Linq to object: ToList can not convert to generic list

Dim tenItem = From t In _InvalidFeeList _ From i In ItemCount _ Where t.FeeCode <> i.FeeCode _ Order By t.Description _ Ascending Take (10) Dim feeList As List(Of AccessorialFee) = tenItem.ToList() I am getting "Can not convert to System.g...

Case insensitive string compare in LINQ-to-SQL

I've read that it's unwise to use ToUpper and ToLower to perform case-insensitive string comparisons, but I see no alternative when it comes to LINQ-to-SQL. The ignoreCase and CompareOptions arguments of String.Compare are ignored by LINQ-to-SQL (if you're using a case-sensitive database, you get a case-sensitive comparison even if you a...

how do you execute a function on a List of objects using LINQ

I want to execute a function on all the objects within a List of objects using LINQ. I know i saw something similar on SO before but after several failed search attempts, i am posting this question ...

How can I Fill a Dataset with data from an IQueryable?

Hi, Is there any quick way to create a table in a dataset and fill it with the schema from an IQueryable (Data is not coming from EF or Linq2Sql)? I need this for binding a grid to my data. Thanks, Roy ...

Why is XPathSelectElement is giving a NullReferenceException?

The following code gives a NullReferenceException since XPathSelectElement can't navigate through the XPath expression I've given: String description = (String)node.XPathSelectElement("//car").Attribute("description"); I've debugged this and verified that the node is being read correctly, and that the elements in my XPath are capitali...

select every 5 records with LINQ

is there a way to select one per every 5 records in sql server with linq? ...

Match closest phrase in SQL

I need to write a query in t-sql or linq that matches db records that contain the most of the user input words. exmaple: nvarchar field in db: "The quick brown fox jumps over the lazy dog" User input: "brown cow" The program would match that record because it has the word brown. let me know if i need to provide more examples. ...

Entity framework execution

Hi, I am new to the entity framework and wondered, when the data is actually taken from the database. If I e.g. does: from order in orderQuery where order select car; is the data then selected from the database, or is it first when I manipulate it like the code below? (from order in orderQuery where order select car).ToList(); ...

change datagrid columns order or index

OK, This is something that I cannot believe I have not been able to figure out -- please tell me I am missing someting simple... I have a datagrid, I am filling it with Linq as well as a custom class to add data to it. Afterwards, I need the data in a specific order - it seems to ignore me. How do I change a columns properties, like ...