linq-to-sql

LinqtoSQL with a where clause containing a List?

Hello All, I have researched this to death. There does seem to be some answers here already, but frankly the answers confuse me. So I'll try to make this as basic as possible. If I have a table in a database, "People" with a name column(string) and an age(int) column. Then I do something like this: List<int> ages = new List<int>();...

Getting stored procedure output parameter with LINQ and Entity Framework

I've created a stored procedure that takes parameters to create a user. If the user already exists it sets the output parameter to 'User already exists' and does nothing more. Now I've mapped this function (InsertNewUser) to my Entity Framework and am calling it like so: context.InsertNewUser(email, name, passwordhash, salt, ???) ...

specify identity value in linq-to-sql

I am trying to set an identity field's value before inserting the new record into the database, I am trying to save having to needlessly re-map all of the FK fields when I know the destination tables are empty already. I had hoped that this question: http://stackoverflow.com/questions/507515/how-do-i-manually-set-an-identity-field-in-li...

Linq query, select inner query into list?

Hello! I am writing a linq query to select a blogpost, from data in dataContext.Blog_BlogPosts join tagsData in dataContext.Blog_TagToPostConnections on data.BlogPostID equals tagsData.BlogPostID where data.Slug == "asp-programmering" select new BlogPost { Title = data.Title, ...

Cannot implicitly convert type 'System.Data.Linq.ISingleResult<CustomeProcedureName> to 'int'

Sorry for this simple question . I have a Stored Procedure that return an int value , I'm trying to call this sp from my asp.net linq to sql project . int currentRating = db.sproc_GetAverageByPageId(pageId); But i get this error : Cannot implicitly convert type `'System.Data.Linq.ISingleResult<PsychoDataLayer.sproc_GetAverageByPag...

Sum of SQL table rows with LINQ ?

There is a table in a SQL database like below : SampleTable : ----------------------- id | number | price ----------------------- 1 | 3 | 300 2 | 1 | 200 3 | 5 | 100 4 | 10 | 10 5 | 30 | 30 6 | 1 | 500 ----------------------- I wanna calculate total price like below : in each row => var SumO...

Simple sql to Linq query with group by and aggregate functions

I'm fighting with linq trying to learn the syntax and I can't figure out how to do the following simple query SELECT DISTINCT user.firstname, user.lastname, COUNT(invoice.amount), SUM(invoice.amount) FROM company_user INNER JOIN user ON company_user.user_id = user.user_id INNER JOIN ...

get the names starts with numbers or special characters in linq to sql

I need to get the list of names that starts with special characters or numbers in the linq to sql query for my asp.net mvc(C#) application. I have tried like this (Which may not be efficient): public List<User> GetUsersStartingWithNonCharacter() { List<User> _dbUsers = this.GetAllUsers(); return _dbUsers.Where(p => ((p.FirstName ...

Timestamp columns and InvalidOperationException

I've recently added a timestamp column to a table in a linq-to-sql DBML file. It caused an InvalidOperationException when the entire web service loaded (no queries were even run). The exception is: [InvalidOperationException: System.Data.Linq.Binary cannot be serialized because it does not have a parameterless constructor.] [InvalidOp...

Group using linq return datatable

i have a linq query that returns Articles ordered by the number of tags that match the current article e.g current article has tags - tag1, tag2, tag3 tagged article 1 - tag1,tag2,tag3 tagged article 2 - tag1,tag2 linq i have is DataTable query = (from row in dt.AsEnumerable() let tags = row.Field<str...

How to insert "empty" row into a DataTable?

I am using a DevExpress LookUpEdit control. My database has two tables that control the population of control options. One called MaintCategory and one called MaintItem. This introduces a Magic Number into my program(the CategoryID) but allows for lots of runtime customization. My problem lies in how to allow my users to un-select ...

Anonymously Hosted DynamicMethods Assembly

Hi, In my mvc web application, I am getting this error: Anonymously Hosted DynamicMethods Assembly Stack Trace : at Read_<>f__AnonymousType14(ObjectMaterializer1 ) at System.Data.Linq.SqlClient.ObjectReaderCompiler.ObjectReader`2.MoveNext() at project.com.Concrete.DetailsRepository.GetDetails(String type) in path Message : The n...

Problem implementing Join(...) extension method

I am trying to use the Join(...) extension method to build a query based on criteria passed to a method. I have an error in the following: public static IQueryable QueryItems(string param1, string param2, string param3) { IQueryable<tbl_Item> query = dataMap.tbl_ItemMap; //Join is giving me the error: Cannot implicitly convert ...

ASP.NET MVC lookup tables in Linq to SQL

This really is an architectural question. I feel like I'm going about this the wrong way and wanted some input on best practices. Let's say I have a Transactions table and a TransactionTypes table. Views will submit the appropriate transaction data which is processed in my controller. The problem is that the logic in the controller may ...

Entity Framework: To be or not to be?..

Hello everyone! I know I'm asking a question that probably has no definite answer, but please, I would like any and all opinions you might have. I used to be a big fan of LINQ2SQL because of it's ease of use. I used to hate creating stored procedures and would use Linq2Sql's lambda expressions instead. But main drawback i saw with L2S w...

Visual Studio 2010 - Can't open O/R Designer

I just got Visual Studio 2010 and need to create a web application using LINQ to SQL. I started writing the web app but can't add a .DBML file to the solution. The option isn't there when I go to Add -> New Item. Am I missing something from the installation CD? Did they change something from Visual Studio 2008? I haven't written in ...

DELETE statement conflicted with REFERENCE constraint

Ok, here is a strange one. I have a routine that goes through and makes several deletions of old data. Ive had a few people complain about getting the error: System.Data.SqlClient.SqlException: The DELETE statement conflicted with the REFERENCE constraint Looking at my code (im using L2S), i dont see how this is possible. But ok,...

Insert Statement / Stored Proc dead locks

I have an insert statement that was deadlocking using linq. So I placed it in a stored proc incase the surrounding statements were affecting it. Now the Stored Proc is dead locked. Something about the insert statement is locking itself according to the Server Profiler. It claims that two of those insert statements were waiting for the ...

Linq 2 sql two same databases

i have two sql servers, with same database, now i want copy some data from one to second. i added to project two linq to sql classes, and now, when i write query i have error because of name collision, how can i avoid it??? ...

DRY up LINQ to SQL code (in specific the orderby)

Lets say I have a table called Projects in my SQL server. My dbml file has the Project object, and I use a list of Projects in multiple views of my MVC application. The thing is: Ordering. By default then you use linq the Projects are ordered by ID. lets say I want them ordered by Name and then by Code. _db.Projects.Ordery(q=>q.Name)...