linq

How to build a dynamic linq query

Hello Everyone, I am trying to find the best way to build a dynamic linq query and populate a list. The user will have about five different fields in which they can choose to filter on. Currently i have the following code: List<TBLPROMOTION> promotionInfo = null; bool active = true; int storeId = 1 using (WSE ...

Entity Data Model & DataGridView - Creating new objects

I'm pretty new to the EDM, so bear with me. I have a windows form that has a DataGridView on it that's bound from the EDM I created. I figured out how to update my changes fine, but it's when the user creates a new row that I'm having a problem. I tried numerous ways and many google searches, but came up with nothing so far. Here's h...

Just wondering what is the reason of InvalidOperationException in Enumerable.Aggregate<TSource>?

Why only one overload throws this exception? Little update: I understand that there was a design decision made by framework developers. The question is really why that decision has been made, is there a related design pattern or whatever? Because if I was designing that I'd return default(TSource). What is wrong with such approach? ...

Linq2Sql loading associated model in a new instance.

Hi all I have a collection of new instances of a linq2SQL object. They were created by the default MVC 2.0 model binder. The created instances include a foreign key to an associated model. The created instance does not include an instance of the associated model. I'd like to populate the associated model based on the foreign key. What is...

How to implement a left outer join in the Entity Framework.

I have the following SQL query:- select distinct * from dbo.Profiles profiles left join ProfileSettings pSet on pSet.ProfileKey = profiles.ProfileKey left join PlatformIdentities pId on pId.ProfileKey = profiles.Profilekey I need to convert it to a LinqToEntities expression. I have tried the following:- from profiles in _dbContext....

C# linq in Dictionary<>

I have an object allStudents = Dictionary<ClassRoom, List<Student>>() In Linq how would I get a list of all the students who are male? (student.Gender=="m") from all the Classrooms? Ian ...

SImplifying with LINQ - Basic selection

Hello foreach (var person in peopleList.Where(person => person.FirstName == "Messi")) { selectPeople.Add(person); } I am just wondering if there is any way to simplify this using LINQ. Like rather than look at all the people I was trying to use LINQ to just fill a list with the "Messi"'s... was trying something like... var s...

JSINQ (Linq for JavaScript library) sub-queries (how-to)

I'm using this library: jsinq. I want to create a new object using subqueries. For example, in .NET LINQ, I could do something like this: from a in Attendances where a.SomeProperty = SomeValue select new { .Property1 = a.Property1, .Property2 = a.Property2, .Property3 = (from p in People where p.SomePrope...

LinQ to objects GroupBy() by object and Sum() by amount

Hello, I have pretty simple case which I started solving using foreach(), but then I thought I could do It using Linq Basically I have IList that contains PaymentTransaction objects and there are 2 properties Dealer and Amount I want to GroupBy() by Dealer and Sum() bv amount. I tried to accomplish this using following code, but unfo...

sql and linq query

Database has tables Photos and PhotoAlbums. I need a query that will select all albums and only one photo from each album. I need SQL and LINQ version of this query. Thanks in advance. ...

CMS/E-commerce asp.net project: one database or multiple databases?

Hi, I'm currently working on an C#/ASP.NET project that will host several differents e-commerce websites, all running in the same application. I use LinqToSql (moving to PLINQO soon) to access my database. The database contains both informations on the website structure (pages, ...) and the products/orders/users data. My question is,...

BindingSource And ComboBox: Combobox Binded on another Source

Hi, I would like to make Something in my form. I have a Binding source binded on Linq to Sql Class. The class Workorder contains one field Site. I would like to display The combobox with all the site, but selected on the site form my workorder. I'm clear? Julien ...

Linq Paging - How to incorporate total record count

Hello everyone, I am trying to figure out the best way of getting the record count will incorporating paging. I need this value to figure out the total page count given a page size and a few other variables. This is what i have so far which takes in the starting row and the page size using the skip and take statements. promotionInfo = ...

How to check if object is sql to linq type

Hi, anyone know if there's any easy way to check if an object is an sql to linq type? I have a method like this but would like it to only accept valid types. public static void Update(params object[] items) { using (TheDataContext dc = new TheDataContext()) { System.Data.Linq.ITable table; if(items.Length > 0) ...

Can't set LinqDataSource InsertParameters from my code behind.

I have the following code that seems like it should set my insertParameter but everytime an insert happens it uses the default parameter. Do i need to do anything special to make this work? Codebehind: protected void SetInsertParams(object sender, LinqDataSourceInsertEventArgs e) { if (lbl_Personnel.Visible) { ...

LINQ to Entities Issue

using(SampleEntities entities = new SampleEntities()) { var userMap = from ad in entities.SampleGroupsSet from uid in distinctUserIDs where ad.ShortUserID.ToLower() == uid.ToLower() select new {shortID = uid, longID = ad.UserID}; string userID = "sampleId"; var longIDs = from map in userMap ...

Linq - How to query specific columns and return a lists

Hello Everyone, I am trying to write a linq query that will only return certain columns from my entity object into a list object. Below is my code which produces an error(can't implicitly convert a generic list of anonymous types to a generic list of type TBLPROMOTION): IQueryable<TBLPROMOTION> matches = webStoreContext.TBLPROMOTION....

Linq to find pair of points with longest length?

I have the following code: foreach (Tuple<Point, Point> pair in pointsCollection) { var points = new List<Point>() { pair.Value1, pair.Value2 }; } Within this foreach, I would like to be able to determin...

EF 4: Removing child object from collection does not delete it - why?

I use Entity Framework 4 and I have parent - child relation with "Cascade Delete" set. So i would expect when i remove a child from the parent that the child is deleted when i call SaveChanges(). cuRepository.Attach(_controlUnit); foreach (var recipe in recipes) { _controlUnit.Recipes.Remove(recipe); ...

ASP.Net MVC Database Driven Menu Strange HTML output

I have a database driven menu Helper that gets called from within my master page: <div class="topBar"> <%= Html.MenuTree(39, false, "first", "last") %> <div class="clear"></div> </div> Below is the code that outputs my HTML unordered list. The problem is that sometimes the output of the menu is completely wron...