linq

Limit rows in table per page

I would like to be able to limit the number of rows that can be in table on View page (I am using ASP.NET MVC), and if there are more rows, it goes to the next page. ...

prevent child tables from being populated in a linq query

Hi, Apologies if this has been posted elsewhere but I can't seem to find any info regarding this. I'm trying to load an object using the LinqtoSql data context. I have a Page and Template table. There is a relation between the two: Page.TemplateId to Template.TemplateID The data context autocreated the Page and Template classes. My ...

LINQ-to-SQL References to Entities in other DataContexts

In my database designs, I tend to have "clusters" of tables. These clusters will typically support one application or group of tightly-functionally-related applications. Often, these clusters also relate to each other through a relatively small number of foreign keys; this helps otherwise independent applications in the business integrat...

Replace Linq to Entity value in Projection

I want to relace a value retrieved from a L2E projection to an expanded string. The table contains a column called Status which can have a value "0" or "1" and in my L2E I have var trans = from t in db.Donation select new DonationBO() { Status = t.Status }; What I want is to return e...

How to identify LINQable parts in pre-.NET 3.5 code?

This is the scenario: I have a huge code-base written in .NET 2.0...and sometime back the migration happened to .NET 3.5. This code-base is both refactored and enhanced as an ongoing maintenance project. I am looking for patterns to identify in code base which are good candidates for LINQ to Objects. I need pointers for comprehensive a...

System.Linq and IEnumerable Group Help

I'm just getting my feet wet with Linq and IEnumerable, and I'm needing help in trying to determine if my objects contain matches for a card game. I think if I get the first one figured out, the other match checking I need to do will fall in place. public class Card { pubic int Value { get; set; } public Card(int value) { ...

LINQ group by expression syntax.

I've got a T-SQL query similar to this: SELECT r_id, r_name, count(*) FROM RoomBindings GROUP BY r_id, r_name I would like to do the same using LINQ. So far I got here: var rooms = from roomBinding in DALManager.Context.RoomBindings group roomBinding by roomBinding.R_ID into g select ne...

Custom Linq Query where property name is unknown at compile time

When I try the following I get an error : Cannot use subqueries on a criteria without a projection. Can anyone tell me how I would create the added expression with the property name to the IQueryable: repository.Query (the type is defined at the class level). private void CheckConstraints(T model, ModelStateDictionary modelState)...

C# File Upload read to memory and use as text file - is there a better way?

I have a intranet hosted web application where the user will upload a text file with space delimited data in 5 columns. I don't wish to save the file so I wanted to just use it in memory. I tried many different examples off the web and none worked. Finally a co-worker showed me how to do this. Here is the code and I'm wondering if there ...

Linq: transform memberExpression type to not nullable

the following member expression type can sometimes be NUllable, I m checking that , however I need to convert it to a non nullable type , MemberExpression member = Expression.Property(param, something); var membertype = member.Type; if (membertype.IsGenericType && membertype.GetGenericTypeDefinition() == typeof(Nullable<>)) { // conv...

Can I do a Where Clause on this LINQ Query?

Dim dataContext As New ACSLostFoundEntities() Dim query = From s In dataContext.FosterForms() _ Join c In dataContext.Fosters() _ On c.License Equals s.License _ Where s.Deleted = "False" _ Select New With {.License = s.License, _ .LastName = s.LastName, _ ...

Linq, Where Extension Method, Lambda Expressions, and Bool's

Greetings, I am having some issues with using a bool operation within a Where clause extension method of an IQueryable object obtained using Linq to Entities. The first example is showing what does work using Bool1 as the operation I need to move to a where clause extension method. The second example is what doesn't work after the chan...

LINQ-to-SQL equivalent to Insert ... Select ... From ... ?

Is it possible to do this in LINQ to SQL in a single command? /* Hello, everyone */ Insert into Messages ( Message, ContactID ) Select Message='Hello', ContactID=ContactID From Contacts (I know I could iterate through Contacts, InsertOnSubmit many times, and SubmitChanges at the end; but this generates one Insert comman...

Trying to convert xml to a dictionary

My xml looks like: <root> <blah1>some text</blah1> <someother>blah aasdf</someother> </root> I want to convert this to a dictionary So I can do: myDict["blah1"] and it returns the text 'some text' So far I have: Dictionary<string,string> myDict = (from elem in myXmlDoc.Element("Root").Elements() ...

Easy way to convert a Dictionary<string, string> to xml and visa versa

Wondering if there is a fast way, maybe with linq?, to convert a Dictionary into a XML document. And a way to convert the xml back to a dictionary. XML can look like: <root> <key>value</key> <key2>value</key2> </root> ...

Query SortedList<Object1,Object2> with Linq

Hi I'm a complete begginer with Linq. And I woild like to know, if it is possible to make a query where for a given Class1.Code I get matching Class2.Value. class Class1() { public string Code; ... } class Class2() { public double Value; ... } SortedList<Class1, Class2> Thank you for your help. ...

Ninject And Connection Strings

I am very new to Ninject and am trying Ninject 2 with MVC and Linq. I have a SqlProductRepository class and all I want to know is what's the best way of passing the connectionstring in the constructor if I am injecting the Repository object in the controller. public class SqlProductRepository:IProductRepository { private Table<Pro...

Single vs. multiple Linq2sql repositories

I have a Users table, Events table, and a mapping of UserEvents. In some parts of my code, I just need user-based stuff. In other parts, I need all of this information. (Especially: given a user, what are the details of each event they are subscribed to?) If I have one repository just for users and another for users + events + userevent...

LINQ and dynamic queries with paging and without LINQ2SQL

I have tried some ways to use LINQ dynamic queries - LINQKit and LINQ Dynamic Query Library. I do not like the second because it some way kills the LINQ idea - to be able to check queries at compile time. And with LINQKit I did not find a good example for my scenario. Also I do not like excessive using of reflection. My scenario is the...

convert comma separated string to list using linq

I have 3 comma separated strings FirstName, MiddleInitial, LastName I have a class NameDetails: public class NameDetails { public string FirstName { get; set; } public string MiddleInitial { get; set; } public string LastName { get; set; } } I have the values for strings as: FirstName ="John1, John2, John3" MiddleInitial...