Removal with LINQ to SQL in Visual Studio

I'm using LINQ to SQL in visual studio to interact with my database. Now I added methods that add, change etc to my code, but I cant make removing a row work. here is my remove method: public bool removeUser(User toBeRemoved) { try { theDBDataContext

Linq makes a very ineffective request within the entity

Entity Framework generates very poorly performing SQL for the following LINQ query: var query = _context.Sessions .Where(s => s.OrganizationId == orgId && s.Device != null && s.Device.User != null) .Select(s => s.Device.User) .Distin

Obtain the same number of elements from the same index

I have two arrays (both the same length) and I'm trying to iterate through each element in both arrays and test if those elements (that have the same index) are equal or not. I want to get the number that are equal and the number that are not equal.

When LINQ Lambdas runs in a foreach loop

So, to keep it short, I have this bit of code in which I loop through the results of a string split and add them to a list, if they have not occurred before in the loop. This is the code. var res = new List<string>(); foreach(string s in input.Split

Implicitly typed local variables must be initialized

Here is the Code :- How to initialize the data? var data; if (mode == "view") { data = (from a in ctx.tblEmployee where a.CompanyId == companyId join b in ctx.tblTO_ShiftSchedule on a.Id equals b.EmployeeId where b.CompanyId == companyId select

Convert the list to the & lt; string & gt;

I have the following problem: public class AwesomeClass { public string SomethingCool { get; set; } public string SomethingUseless { get; set; } } I have a class which contains a number of properties, and I need to convert a list of these classes int

Compare two sets of data from different databases using VB.NET

For data assurance, my task is two compare two datasets from different databases. Currently I am performing the cell-by-cell value comparison which is a Brute Force method and is consuming lot of time. I would like to know if there are any methods wh

How to group a list of grouped lists?

I need a grouped list of grouped lists; I have a bunch of articles that I need to group by year, and group by month within each year. It will look something like this on the page: 2015 February Article 1 Title Article 2 Title January Article 3 Title

How do I return an incomplete object?

My select statement does not return the entire Customer object, just the utrustningNr and beskrivning. How do i return it in a correct way without getting this error: Cannot implicitly convert type 'System.Collections.Generic.List<AnonymousType#1>'

Running a stored procedure using linq in c #

I made a stored procedure in sql server 2008 which gives me the changes made to a table. I am using Linq to SQL to use this table in C#. my stored procedure is CREATE PROCEDURE dbo.getlog -- Add the parameters for the stored procedure here @p1 int =

Using FirstOrDefault () in a Where clause ()

I've got a LINQ query that's returning no results when I know that it should be returning at least one. I'm building up the query dynamically. I looked at the result set in the debugger right before I get to the line that filters out all of the resul

Double selection in the list

How can i select name in list? which is itself in list??? My struct: public class Item { int id; List<Name> names; } public class Name { int id; string name; } List<Item> Items; code: Items.Select(a => a.id = 1) //whats next Assuming you wa

Consultation not to return anything

I have 2 tables: winery and wineType (in wineType I have foreign key for winery, called wineryID). I try get all winery names that produce wine like the one the client selected from drop down list. And I have this function public void ispolniLista()

Selecting a column value in LINQ TO SQL

I have query in link to SQL like this var password = (from userAccounts in myDb.Physicians where userAccounts.Phy_UserName == txtUserName.Text select userAccounts).FirstOrDefault(); I want to select a specific column with that query, I want to retrie

C # Using .Select and .Where in a single LINQ statement

I need to gather Distinct Id's from a particular table using LINQ. The catch is I also need a WHERE statement that should filter the results based only from the requirements I've set. Relatively new to having to use LINQ so much, but I'm using the fo

LINQ - View about 6000 unique records by the WHERE clause

I've got a problem and no idea how to solve it. Imagine you have a List<int> with about 6000 unique id's that matches the id's of a table with about a million records in a sql datatable. I want to select those 6000 records that matches those id's vi

LINQ to Entities Does Not Recognize Method Exception

I have some thing like this SecuritySearcher sc = new SecuritySearcher(); Dictionary<string, bool> groupsMap = sc.GetUserGroupMappings(domainName, currentUser, distGroups.ToList()); IQueryable<HotelTravel> groupq = (from hotel in qHs join hp i

LINQ to SQL group people by age

Sample in C# and VB.NET are OK. I have a table "People" with the following columns: -FullName (nvarchar not null) -DOB (datetime null) I want to write a LINQ to SQL to group the people by age, like following result: Age 19: 4 ppl Age 20: 5 ppl A

Linq to EntityFramework DateTime

In my application I am using Entity Framework. My Table -Article -period -startDate I need records that match => DateTime.Now > startDate and (startDate + period) > DateTime.Now I tried this code but its now working Context.Article .Where(p =>

Why is Null an invalid LINQ projection?

I had the following statement, which always returns null: var addins = allocations.SelectMany( set => set.locations.Any(q => q.IsMatch(level, count)) ? (List<string>)set.addins : null ); I changed it slightly, and now it works fine: var addins

String or binary data would be truncated errors

I'm using Linq to SQL with SQL 2005. I'm parsing a large fixed width file and importing the data into SQL via custom entities that I have mapped to the database using property attributes. The program runs for about 240 records before throwing this er