linq

How to select items that do not show up in a second list with Linq

I have two lists and I want to select items that are not in the second list from the first list. I have no Linq experience to I think this should be a good way to start learning. ...

LINQ to SQL and Join two tables with OR clause

Let's say I have Plans and Documents Dim myPlans = _context.Plans.Where(predicate1) Dim myDocuments = _context.Documents.Where(predicate2) I have structured the where clause for each using PredicateBuilder. So, myPlans and myDocuments have a correct SQL statement. What I'd like to do is join these two tables into one linq statement. ...

Transactions in LINQ to SQL

Hello guys, I need some help regarding transactions in Linq to sql. Below is the typical transaction layout. If any operation fails, then all the operations are rolled back. mainTransaction (tScope) Operation 1 changes db.submitChanges() Operation 2 changes db.submitChanges() ... catch(TransactionEx...

Join 2 lists by order instead of condition in LINQ

How can I join 2 lists of equal lengths (to produce a 3rd list of equal length) where I do not want to specify a condition but simply rely on the order of items in the 2 lists. Eg how can I join: {1,2,3,4} with {5,6,7,8} to produce: {{1,5}, {2,6}, {3,7}, {4,8}} I have tried the following: from i in new []{1,2,3,4} from j in new [...

C# Linq Code Refactoring

The code below is what I currently have and works fine. I feel that I could do more of the work I am doing in Linq instead of C# code. Is there is anyone out there who can accomplish the same result with more Linq code and less C# code. public List<Model.Question> GetSurveyQuestions(string type, int typeID) { using ...

Linq to Entities Filtering an Entity Dynamic/Strongly Typed

I am binding a Winforms Grid to an entity. (For reasons I won't go into here it must be bound to the entity, not the result a query) The code is as follows: grid.DataSource = myEntities.entityName.Where("it.field = " & field) It works, but it obviously isn't strongly typed. Is there a way to define the Where clause of an entity usin...

Update SubmitChanges() - does not update.

With this code there is no change in my database. when the above code is run there is no longer a new entry created neither is an entry updated. public void UpdateCallback(callback cb_) { callback call = context.callbacks.Single(c => c.callbackID == cb_.callbackID); //call.callbackID = cb_.callbackID; ...

Using LINQ Expression Instead of NHIbernate.Criterion

If I were to select some rows based on certain criteria I can use ICriterion object in NHibernate.Criterion, such as this: public List<T> GetByCriteria() { SimpleExpression newJobCriterion = NHibernate.Criterion.Expression.Eq("LkpStatu", statusObject); ICriteria criteria = Session.GetISession().CreateCriteria(typeof(T)).SetM...

LINQ UpdateCheck on parent "LastUpdatedOn" field while updating children

Is it possible to set "UpdateCheck" to "LastUpdatedOn" field of parent object while updating children? ...

insert 2 table in single query in linq

hi, i need to insert two table object in single query is it possible to do in linq. At present i am using insertonsubmit() 2 times. ...

Why is LINQ to SQL entity association creating a new (duplicate) row when inserting a new record?

I am trying to insert a new entity using LINQ-to-SQL, and entity is associated with a User entity. The insert of the new entity is successful, but my existing User entity gets inserted as if it were a new User. The code looks something like the following: var someEntity = new Entity(); someEntity.User = this.User; dataContextInstance.So...

Change app.config at install time

How can I dynamically change a connectionString in the app.config file? I have an application written with windows forms, c# 3.0 and Linq to Sql. I need to change the connection string when i install the application. How i do this? When the user installs the program it must show a form with an option to change the connection string if...

Load image to ReportView dinamic.

Hi, My name is Ed and i need load image from ReportView dinamic.How i can do this? I work windows forms,c# 3.0 and linq to sql, i need load image to my reports dinamic. Thanks. ...

Generic way to find or create an object in Linq to Sql?

Quite often in my Linq to Sql code, I need to "find or create" an entity as such: var invoiceDb = ctx.Invoices.FirstOrDefault(a => a.InvoicerId == InvoicerId && a.Number == invoiceNumber); if (invoiceDb == null) { invoiceDb = new Invoice(); invoiceDb.Number = invoiceNumber; ct...

How do I decipher the Select method docs on MSDN?

I'm struggling to get my head around LINQ and have come to the conclusion that searching through dozens of examples until I find one that is near to my own application in C# is not teaching me how to fish. So back to the docs where I immediately hit a brick wall. Can someone please help me decipher the Enumerable.Select method as prese...

LINQ Join to find items NOT IN a list

How do I use LINQ across Queryable and non-Queryable data? With the following code I want to end up with a list of unselected users, i.e. everyone in allUsers that is not in selected. public IQueryable<CompanyUser> FindAllUsersNotAssignedTothisCompany(int companyID) { var allUsers = Membership.GetAllUsers(); var selected = db.C...

LINQ and dbml file

Is there any relation with LINQ and dbml file.someone telling that using Linq in project .Actually that project containing one dbml file,inside that one .cs file,one dbml.layout and designer generated code.Actually notation is something like var numQuery = from num in numbers where (num % 2) == 0 sel...

break an IEnumerable<int> query which uses Enumerable.Range

Hi I have this following IEnumerable LINQ query: var query = from p in Enumerable.Range(2, 1000000) let sumofPowers = from ch in p.ToString() let sumOfPowers = Math.Pow(Convert.ToDouble(ch.ToString()), 5) select sumOfPowers where p == sumofPowers.Sum() select p; It finds the sum of all the numbers that can ...

What winforms control should I use to display a table of search results returned from LINQ?

What control should I use when wanting to display a list of record information (Name, ID #, date)? It is about 5 small columns, and I'll have many rows returned. I'm using LINQ to grab the records I need from the database and have it currently in an IQueryable. Can anyone suggest what WinForms control I should be using in this case ...

LINQ Confusion - Database not persisting after the application closes?

I'm making a WinForms app in C#. When I go to create my database object, I'm presented with two options: Local Database Service-based Database All I want is a simple local database to use for my project. However, if I select "Local Database (Compact Edition)" then after I create my tables and drag them over to a LINQ-To-SQL Class...