linq-to-sql

LINQ-To-SQL - Is it possible to cache GetTable or serve it from repository?

Hi, I'm running profiler tools on the LINQ-to-SQL data access layer. A lot of the time is spent on GetTable<clsName>() because it's being called each time i CRUD data. Is it possible to cache GetTable<clsName>() for all the tables when the application starts or serve it through some sort of repository where it will be in memory? Th...

How to match a NULL column using LINQtoSQL and lambda?

Hey there SO, I'm having a heckuva time trying to match rows where a column is null. I know that in SQL, I have to use the IS keyword to find null columns: SELECT * FROM Categories WHERE ParentCategoryID IS NULL; I'm trying to recreate the above query in LINQtoSQL. I've tried: var RootCats = categoriesRepository.Categories .Wher...

How can I wrap tables into a more generic class for use with multiple data contexts?

I have two different DataContexts (SQL Databases) that have the same data, just with slightly different naming: DB1: Serialnumber Productnumber DB2: SerialNumber ProductNumber Result So I want to be able to wrap these tables in a class that will let me get back the serial number and product number regardless of the DataContext that it ...

Is it possible in LINQ to SQL to create a computed column using DataContext.CreateDatabase?

I want to dynamically create a database using my DataContext's CreateDatabase Method. I have manually created mapping classes and tested them. But as soon as I add the Expression Column (see below) the creation fails with an SqlCeException and I am unable to find out the exact reason. /// <summary> /// The sum of ratings for thi...

Help with converting tsql query to linq2sql

Hi everyone! I want to convert following T-SQL query to Linq to SQL but don't know how select c.CATEGORY_ID, c.NAME, c.DESCRIPTION, COUNT(*) as PRODUCT_COUNT from CT_CATEGORY c inner join CT_CATEGORY_PRODUCT cp on c.CATEGORY_ID = cp.CATEGORY_ID inner join PRODUCT p on cp.PRODUCT_ID = p.PRODUCT_ID group by c....

Calculating DateTime with LINQ to SQL

Hi, I have two tables TimeSheet and TimeRecord. TimeRecord has Foreign Key TimeSheetId of TimeSheet. The following time-logs are from TimeRecord, TimeSheet sample data: TimeSheetId, StudentId 187 , 10 196 , 11 195 , 12 TimeRecord sample data: TimeRecordId, TimeSheetId, TimeIn, TimeOut 1 , 187 , 8/17/2010 1:06:55 PM , ...

Design question regarding Dependecy Injection and reuse of a single data context

I'm currently just starting to implement Dependency injection so i can start testing my code and have come across an issue many of times that i cant figure out. My current case scenario: I have a single class ( foo.cs ) that is active the whole time a windows service is running. Its responsible for polling the db for new messages then ...

Violation of PRIMARY KEY constraint Cannot insert duplicate key in object . In C#.net....Visual Studio 2010...framework 3.5...

I'm Developing a small windows application in C#.net....Visual Studio 2010...framework 3.5... i use Linqtosql for database manipulation..... table name:cprofile Fields of the table are: custid int (primary key), custname varchar(50), address nvarchar(MAX), mobileno nchar(10) So i hav...

what cast is missing in linq syntax?

tblUserRole Permission = (oCurrenUserPermission.GetPermission(Convert.ToString(Session["Navigation"]))); if (Permission.IsInsert == 1) { } public IQueryable GetPermission(string sPageName) { IQueryable query; #region MyRegion query = from r in this.Context.tblUserRoles join p in this.Context.tblPageInfos on...

Does LINQ have an equivilant of @@IDENTITY or SCOPE_IDENTITY()?

Say that a page loads and the first thing I want to do is find the identity of the last record inserted into a table. I'm not going to be inserting any records or anything, i just want to come in blind and find the last id inserted, can it be done using LINQ? ...

How to get records affected by an update stored procedure in LINQ to SQL

I'm executing an update stored procedure from LINQ to SQL and I need to know the records affected after the update is called. I'm using dbml designer to generate the LINQ code. ...

Get only two decimal points in money datatype in SQL Server

SELECT ROUND(123.4567, 2) gives me 123.4600. But I need 123.46. Data type of field is money. SOLUTION <%#DataBinder.Eval(Container.DataItem, "FieldName","{0:0.00}")%> ...

System.Linq.Dynamic and Sql IN operator

I am using the System.Linq.Dynamic library to power a GUI base query engine however I can't seem to find support for the equivalent of the Sql IN operator. Has anyone used this? I have searched and found a couple of possible duplicates here however none have been exactly what I am asking (or have been solved). Clarification: I am usi...

capture output parameter from stored proc in LINQ To SQL ExecuteQuery

Is it possible to get an output parameter back from the LINQ To SQL DataContext when you execute a stored procedure? IEnumerable<Address> result = ExecuteQuery<Address>(((MethodInfo)(MethodInfo.GetCurrentMethod())), address, pageIndex, pageSize, totalCount); where address, pageIndex and pageSize are input parameters, and ...

Linq to SQL Entity stored in a ViewState problem

Hello, I'm trying to stored a Linq To SQL Entity within a ViewState. However when I do so, it results in the following error: Error serializing value 'System.Collections.Generic.List1[RequireApps.RequireLinqDataAccess.GroupMember]' of type 'System.Collections.Generic.List1[[RequireApps.RequireLinqDataAccess.GroupMember, RequireApps.Req...

Code generated by sqlmetal makes NOT NULL primary key columns Nullable

I'm using sqlmetal.exe to generate a DataContext class from a sqlserver database to use with LINQ. I have a bunch of stored procedures that in some cases returns a primary key column that is a NOT NULL INT, such as this one: CREATE PROCEDURE spDDIs_Find(@DDINumber VARCHAR(64)) AS IF NOT EXISTS (SELECT ID FROM tDDIs WHERE DDINumber = @D...

Using LINQ to SQL group, sum and aggreate all together

Hi, I have two tables Students and Origami. Origami has Foreign Key of Students table. Each student can make one or more origami for each month. Students sample data: StudentId, FirstName, LastName 187 , John , Maslow 196 , Crystal , Hood 195 , Sarah , Lewis Origami sample data: OrigamiId, StudentId, CreationDate, NumberOfOriga...

Using First() with OrderBy and DynamicQuery in One-To-Many related tables

Note: I realize this question is similar to another question, however that question was asked in the context of Genom-e and remains unanswered. My question is in the context of LINQ DynamicQuery. I'm using the String extension method overload for OrderBy provided by System.Linq.Dynamic. Passing a String Literal to OrderBy works g...

Dynamicallly building Linq where clause....

Hi, I am trying to do something that can be done conventionally by writing extra lines of code. I have seen few samples on this website that addresses my question but still i cannot put all the pieces together to solve what i am trying to achieve. Here is pseudo code of what i am trying to do: list<t> searchTerms; class t { string ...

Linq-to-SQL Database Update Fails

Very simple update. It simply fails, no error, no change gets made to the database. Dim db As New BarClassesDataContext Dim foo = (From a In db.articles Where a.id = 14 Select a).Single Response.Write("<h3>" & foo.title & "</h3>") foo.title = "This is my new, updated title for article ID #14" db.SubmitChanges() Here is the relevent po...