linq

Custom Generic.IEqualityComparer(Of T) - Compiler Errors

I am trying to implement a simple IEqulityComparer to use with LINQ collections. I have written the following code which is reduced to its simplest form for discussion purposes... Public Structure bob Dim SiteID As Integer Dim fred As String End Structure Public Class insCompare Implements System.Collections.Generic.IEqual...

LINQ Except using custom Comparer.

I am trying to use the "Except" method on a LINQ result set using a custom implementation if IEqualityComparer to exclude certain results based on the value of a single field from the result set. So, in simplified form I have... '' Get collection of published sites... Dim List1 = (From i In db.Sites _ Where (i.StatusID =...

Extending System.Data.Linq.DataContext

I have a class reflecting my dbml file which extends DataContext, but for some strange reason it's telling me System.Data.Linq.DataContext' does not contain a constructor that takes '0' arguments" I've followed various tutorials on this and haven't encountered this problem, and VS doesn't seem to able to fix it. Here's my implemen...

What is the easiest way to fixed pivot transform this data in C# (linq?)?

Given this example data (in .NET classes where Po, Sku, Qty are properties): PO, Sku, Qty 1,ABC,1 1,DEF,2 1,GHI,1 1,QWE,1 1,ASD,1 1,ZXC,5 1,ERT,1 2,QWE,1 2,ASD,11 2,ZXC,1 3,ERT,1 3,DFG,1 3,DFH,1 3,CVB,4 3,VBN,1 3,NMY,1 I need to transform it into a fixed column format, with a max of 5 SKUs per line (repeating the PO if needed for > 5)...

How do I use my enumeration in a LinqToSQL query?

I have a field in my database table that use to store an enumeration value, e.g.: create table MyTable ( ... Status tinyint not null, ... ) and in my C# class I have public enum TStatus : byte { Pending = 1 Active = 2, Inactive = 3, } public TStatus MyStatus { get { return (TStatus)Status; } set { Status = (byt...

Linq .Contains with large set causes TDS error

I've oversimplified this a bit, because I'm looking for a general-purpose answer. Let's say I've got a table setup like this: Parent recno int (unique, pk) date datetime stuff varchar(50) Child parentrecno (int, fk) --- PK sequence (int) --- PK data varchar(50) And in my C# program I've gone through a lot of...

Take a sequence of elements from an array from i to j using C# and extension method

I have an Array<string>. I have to take all elements from i to j. How can I make this using an extension method? ...

LINQ to SQL and Attaching Child Objects

I am writing a class that will (hopefully) allow manipulation of data through a LINQ to SQL layer without having to know what individual objects you are working with. So far, it works fine for cascading selects and inserts, but I am having a hard time with updates. Here is the save method I am using: if ((long)entity.GetType().GetProp...

How do I cache an IQueryable object?

I've got this method that returns a Linq-to-SQL query for all the rows in a 'UserStatus' table: public IQueryable<BLL.Entity.UserStatus> GetAll() { var query = from e in _SelectDataContext.UserStatus select new BLL.Entity.UserStatus { UserStatusId = e.UserStatusId, En...

Temporary tables in Linq -- Anyone see a problem with this?

In trying to solve: Linq .Contains with large set causes TDS error I think I've stumbled across a solution, and I'd like to see if it's a kosher way of approaching the problem. (short summary) I'd like to linq-join against a list of record id's that aren't (wholly or at least easily) generated in SQL. It's a big list and frequently ...

Linq question about grouping something that can change?

I have a list of multiple string and I need to do operation on them by the suffixe they have. The only thing that is not changing is the beginning of the string (They will be always ManifestXXX.txt, FileNameItems1XXX...). The string end's with a suffix is different everytime. Here is what I have so far (Linq Pad): var filesName = new[] ...

Need help on developing LINQ Lambda expresssion to filter on a Schedule

I am having a hard time finding the lambda expression to call on a list to correctly filter an object structure. I was hoping someone here could help out. I am using .NET 3.5, and LINQ and the object domain is set up from Linq to SQL DBML. I specifically want to use lambda expressions. The object structure is one where persons have s...

Selecting all child objects in Linq

This really should be easy, but I just can't work it out myself, the interface is not intuitive enough... :( Let's say I have a State table, and I want to select all Counties from multiple States. In SQL that would be: select c.* from State s join County c on c.StateCode = s.StateCode where s.TimeZone = -5 -- or some other criteria...

merge 2 Linq sequences into one, with precedence

I have 2 sequences, each of which returns an anonymous type with 2 fields (call them x and y). Semantically, x serves as a key and y a value in both of these sequences. How can I specify that the first sequence has precedence over the second in case the same x appears in both, and thus merge them into 1 sequence? ...

Linq to XML (Base64 Encoded)

I have got to convert a PDF to a Base64 Encoded and write it to a element in a XML file. I have got the Base64 Encoded string (very long/big) but the spec im working from says the following: This has been chosen, to ensure the XML file may be displayed and validated without any potential problems caused by the handling of the raw binary...

Linq + Invalid expression term '>'

Can anyone help me here, the following works fine on my xp but not my vista machine. Im querying a Generic dictionary. Both computers have .NET 3.5 + SP1, 3.0, 2.0, etc., and have the web project targeted to 3.5 Framework. using System.Linq; string val = "Test"; var d = DictionaryOfStuff().Where(n => n.Key.ToLower().Contains(val.ToLow...

LINQ to SQL and Data Projection, MVC

HI I have a table with some some values (IDs), and of course when i get the result i got just the int IDs, but i want to put it more user friendly, for example when its the number 1, i want to put the string "Avaible", when its 2 "Not avaible", im on an N tiers enviroment and i need to get this done on the Model, whats the best way to a...

linq 'range variable' problem

Hello all, I have a strange problem when deleteting records using linq, my suspicion is that it has something to do with the range variable (named source). After deleting a record all targets for a customer are retrieved using the following statement: var q = from source in unitOfWork.GetRepository<db_Target>().Find() where source.db...

Updating Linq data

I have one Windows application and one Web application running on same database but two dbml files(Linq). Now when i update data in windows application, i could not see the updated data in web application. If i rebuild the web application, i am able to see the data. But after deployment, the web application should run without any manual ...

How to use TypeMock Isolator with Linq to SQL and DataContext

Hi, i am using TypeMock Isolator to fake the tables on my DataContext like this: Isolate.Swap.CallsOn(ctx.GetTable<TTable>()).WithCallsTo(content); I now can fill the "database" with arbitrary data on each test. In order to get meaningful data for the test scenario into the DataContext i usually have to create 3-5 objects. Now, the p...