linq-to-sql

Multiple WHERE's in same LINQ 2 SQL Method

I have the below LINQ Method I am trying to create. The issue seems to be the Second WHERE clause. I am getting this error --> Cannot implicitly convert type 'System.Collections.Generic.IEnumerable<MatrixReloaded.Data.CMO.tblWorkerHistory>' to 'bool' I also had && there vs WHERE but I was getting a similar error. I don't NEED anyth...

Improving an insert method

I'm wrote an insert method that uses linq and loops through 2 lists, the first being able to go up to 14k objects and the send about 8k objects. Whenever I run this method, I always get "Transaction Timeout Exception". Can you help me improve this? public void InsertNewInventoryGoodsEvents(List<GoodsEvent> eventsList, List<InventoryGoo...

LINQ many to many hell - querying where CONTAINS ALL

I have a many to many relationship as follows: Products ProductID Description ProductFeatures ProductFeatureID ProductID FeatureID Features FeatureID Description Any Product can have many Features. I then come along with an iQueryable called "SearchFeatures" which contains two particular Feature objects that I want to search on. I ...

Selecting multiple one to many relationships in LINQ to SQL using outer joins

I'm using .NET 4 and VS 2010 and have the same issue in .NET 3.5/VS 2008 The structure: Table 1: Call Table 2: AddressChangeRequest Table 3: CallNotes A single Call can have many AddressChangeRequests and many CallNotes. A Customer (customerKey) can have many Calls. The LINQ code: return db.Calls.Where(c => c.CustomerKey == '....

Understanding .AsEnumerable() in LINQ to SQL

Given the following LINQ to SQL query: var test = from i in Imports where i.IsActive select i; The interpreted SQL statement is: SELECT [t0].[id] AS [Id] .... FROM [Imports] AS [t0] WHERE [t0].[isActive] = 1 Say I wanted to perform some action in the select that cannot be converted to SQL. Its my understanding...

LINQ To SQL - get latest records that match a where clause

Given something like the following (just thrown together as an example) Employee ID | Time In | Position | Shift Length 1 | April 1 08:00 | Manager | 8 0 | April 1 08:00 | Maint | 8 1 | April 2 08:00 | Manager | 8 2 | April 1 08:00 | Clerk | 4 1 | April 3 08:00 |...

ASP.net MVC displaying results from two tables on one view

Hello I'm crating a simple MVC app that has People and Notes tables. Using the repository method and LINQ to SQL to access the data. Each person has a single note for a day and the note has a CreatedAt. Foreign Key in Note table as PersonID. I have managed to get CRUD working for both Person and Note independently but I'd like to be ...

Linq: To join or not to join (which is the better way, joins or relationships)

I have written quite a bit of code which uses the Linq2Sql table relationships provided to me just by having foreign keys on my database. But, this is proving to be a bit laborious to mock data for my unit tests. I have to manually set up any relationships in my test harness. So, I am wondering if writing Linq joins rather than relying ...

Basic LINQ to SQL Question: How to call stored procedure and retrieve single return value.

I'm new to LINQ and am having a problem getting proper results from a simple (working) stored procedure that takes no parameters and returns a single Integer. When calling this sproc with LINQ its returnvalue is always 0. When run using tableadapter or directly on the sql server it works, returning 6 digit values like 120123. Here is ...

Linq to SQL using StoredProcedure - How to return a value (insert, update, delete)

How do we return a value from a stored procedure here is my sp looks like: create proc dbo.spInsertGroup @ID uniqueidentifier @GroupName varchar(100), @IsActive bit AS BEGIN insert into tblGroup values(@ID, @GroupName, @IsActive) Select @@IDENTITY AS ID END based on the return value i want to show the user some kind of feedback ...

linq-to-sql fails if local list variable

I'm struggling to get what I thought would be a simple LINQ-to-SQL query to work. I can construct the query ok and can verify that the SQL it generates is correct but when executing get the dreaded "System.NotSupportedException: Queries with local collections are not supported" exception. I've simplified my query but in short the query ...

Using SQL Server 2008 R2 with Visual Studio Express

I want to create either "LINQ to SQL" classes or use "Entity Framework" from Visual Studio Express 2010. When I attempt to add a data source my only options are: "Microsoft Access Database File" "Microsoft SQL Server Compact 3.5" "Microsoft SQL Server Database File" Do I need VS2010 Pro to use LINQ to SQL or EF? I thought I could d...

Is it possible to let linq to sql auto submit my new records back to database ?

I am using linq to sql , and I return a queryable result from linq to sql : var qry = from p in table select p; Then I use this to bind to a xtragrid: GridControl.DataSource = qry; Then If I edit the records in xtraGrid, I just need to call dataContext.submitChanges() to submit the changes back to database. My question is : Am I ...

Improving method performance

I wrote the following method that receives a list and updates the database based on certain criteria: public void UpdateInventoryGoods(List<InventoryGoods> list, int id) { int index = 0; var query = from inventoryGoods in context.InventoryGoods where inventoryGoods.ParentId == id...

Incorrect EntitySet when using foreach instead of select

I've got a very basic database schema and have created a dbml from it. Two tables are related in a one-to-many. (A)1-*(B) ... hence each A gets an EntitySet called "BSet". If I do: foreach (var a in db.A) { Console.WriteLine(a.Name); foreach (var b in a.BSet) { Console.WriteLine(b.Number); } } I find that it prints out t...

SQL to LINQ simple query?

Hi below is a sql server table, which is used to hold users prediction for soccer matches. a user can predict either a home win, an away win or a draw/tie for a specific soccer match. how can i query this table to find the top 3 predictions, the top 3 games must be distinct gameId's either SQL or LINQ solution would be much appriciate...

LINQ to SQL Insert Failing because of Join

I've got two tables in my database Users and HealthMonitor. In the HealthMonitor table I have a UserID field that is mapped to the ID field in the Users table. Pretty straight forward so far... I left the UserID field in the HealthMonitor table as "Nullable" so that I can have the system insert a NULL value into the table if there is ...

Linq update query - Is there no pretty way?

Hello I want to update my database using a LINQ2SQL query. However this seems for some reason to be a very ugly task compared to the otherwise lovely LINQ code. The query needs to update two tables. tbl_subscription ( id int, sub_name nvarchar(100), sub_desc nvarchar(500), and so on. ) tbl_subscription2tags ( sub_id (...

Asp.net profile ProfileBase GetPropertyValue performance issue in linq statement

I has method which should return users with highest points. Points are stored in aspnet_Profile table, so i can get these points in the way like this: ProfileBase.Create(mu.UserName).GetPropertyValue("Points"). So at first i call IEnumerable<MembershipUser> users = Membership.GetAllUsers().Cast<MembershipUser>(); and then (i'm usi...

SubmitChanges() doesn't work

Hi , I don't know what's wrong with this code , this code compile successfully but doesn't update database . do i miss some thing ? DataClassesDataContext db = new DataClassesDataContext(); var query = from p in db.AllPatiences select p; int newID = 1001; foreach (AllPatience patient in query) { patient.Id = newID.ToS...