linq

Linq to jet oledb for microsoft access

Possible Duplicate: Query Microsoft Access MDB Database using LINQ and C# hi is anyone who knows linq to jet-oledb for microsoft access ? ...

What is the complexity of this LINQ example?

Hi guys. I am wondering about general performance of LINQ. I admit, that it comes handy but how performant is LINQ? I know that is a broad question. So I want to ask about a particular example: I have an anonymous type: var users = reader.Select(user => new MembershipUser(reader.Name, reader Age)); And now, I want to convert it to t...

How to optimize this LINQ query for Visual Studio?

I have this one gigantic complex LINQ to SQL query that I need to optimize somehow, because the background C# compiler completely hogs the CPU and I can't type or edit my .cs file normally in Visual Studio 2010 (every letter, especially if IntelliSense wants to pop up, lags horribly). The culprit is this: var custFVC = (from cfvc ...

Collection of strings to dictionary

Given an ordered collection of strings: var strings = new string[] { "abc", "def", "def", "ghi", "ghi", "ghi", "klm" }; Use LINQ to create a dictionary of string to number of occurrences of that string in the collection: IDictionary<string,int> stringToNumOccurrences = ...; Preferably do this in a single pass over the strings colle...

Linq Optimization for Count And Group By

Hello, i've written written a code for counting each byte frequency in binary file. Using Linq. Code seem to slow when performing the Linq expression. Its seem hard to implement Parallelism on this kind of logic. To build the freq table over 475MB it took approx 1 mins. class Program { static void Main(string[] args) { D...

linq SingleorDefault

I want to return a single row from the users table using domain account id as my primary and unique key However when i use singleordefault and see its sql translation it performs entire select * from Users my query is.. var user = base.SingleorDefault(t=>t.domainaccountid) i want this to return just one row! ...

How to erase all records from a database when using LINQ and tableadapter?

Hi, I am trying to load data from Excel file to DataGridView in my Form. First I load all data from excel sheet into dataset then put all that data in database using C# LINQ and then I just set the DataGridView.DataSource to name.BindingSource and that is it. I get all the data in DataGridView but when I try to load the data again (I ha...

How to enforce unique constraint with LINQ to SQL

Hi, I'd like to enforce a unique constraint on two columns with LINQ to SQL. I have got a constraint configured on a SQL table, but is there a way to use it with LINQ to SQL? Unique constraint is applied to two columns, both of which are foreign keys. Thank you Edit: I could catch exception, that's if a very specific exception gets t...

LINQ Join on top 1

I've got three objects (splistitemcollection) that im joining together which is working great but the problem im having is that there are a one to many relationship between the a contract object and a customers object. I need to grab just just the first customers object for each contract object during the join. Here is what I am getting...

When to use Cast() and Oftype() in Linq

I am aware of two methods of casting types to IEnumerable from an Arraylist in Linq and wondering in which cases to use them? e.g IEnumerable<string> someCollection = arrayList.OfType<string>() or IEnumerable<string> someCollection = arrayList.Cast<string>() What is the difference between these two methods and where should I apply...

ASP.NET MVC2: Database Result Scoring Methodology

One of the projects I am working on is a search engine. This search engine has 36 parameters that can be set to a search within the form, and results are displayed through a series of scoring mechanisms. For example, if you were searching for a desk with a certain width, it would find the desks closest to the desired width and then sor...

How to make a Linq sum

Hi, I'm having a problem with a LINQ expression. With this class: class MyClass { public string of { get; set; } public string order { get; set; } public int qty { get; set; } public override string ToString() { return string.Format("OF: {0}, Order: {1}, Qty: {2}", of, order, qty); } } and I want to ...

Linq join, group, count where count greater than value

I have the following linq expression that lets me join two tables, group them by a "DSCID", and then get a count of the grouped values: var qryGeoApppendCount = from a in append join g in geo on a.Field<string>("RNO") equals g.Field<string>("RNO") group g by g.Field<i...

MVC Model with Relational database

I am creating this MVC model and trying to understand best way to do it.How should I get related data when I have relationships between tables.For example in code below I have created a formviewmodel and I am calling function to get all images in Images table for a user. Should I instead keep images property of Users model and fill that ...

Count in lambda expression

I am trying to run a query where I get the name of locations and the number of items in that location. So if i have a program that contains 3 locations I want to know how many programs are in that location..I need to use this with a lambda expression or linq to entities. return Repository.Find(x => x.Location.Name.Count())...clearly mis...

LINQ to SQL advice - why won't it work?

I'm trying to write a LINQ query that that simply gets the count of rows where a variable ('id') is equal to the JOB_GROUP statement. Problem is, Visual Studio is returning an error on the ; at the end, saying 'Only assignment calls.....may be used as a statement'. Is there anything obvious wrong with my query? var noofrows = from s in ...

Method to determine if keys of a dictionary are in sequence or a range.

I'm trying to determine when to remove entries in the sorteddictionary, when a sequence is found, i.e. where the key is a sequence of 1,2,3,4,5,6,7,8,9,10... etc. I have: SortedDictionary<int, string> Its hard to explain. I'm adding pairs where the key can be any integer value, generally on a random'ish basis. So, the program may ...

Why predicate isn't filtering when building it via reflection

I'm building a rather large filter based on an SearchObject that has 50+ fields that can be searched. Rather than building my where clause for each one of these individually I thought I'd use some slight of hand and try building custom attribute suppling the necessary information and then using reflection to build out each of my predica...

Rhino Mock OfType<>

Hi, Im trying to test this statement IStudentAssessmentUnitStatus res = student.UnitStatusList.OfType<IStudentAssessmentUnitStatus>(). FirstOrDefault(s => s.ID == unit.ID); Inside the list there could be multiple types hence the OfType. However when testi...

How to use .Top() with Code First

Is this possible with Code First? I could do this if I only used Entity Framework: var q = from m in context.Products .Top("0") select m; ...