linq-to-sql

existing application, can I just start using linq-to-sql? any tips on integration?

Hi, I have an existing web app that has a data layer and a bll that calls the data layer. The data layer is ado.net that calls stored procedures. I created another project in vs.net for linq-to-sql, dragged all my tables over. Would it be wise to just start using linq or should I spend the time and re-write all the db logic in linq ju...

How to do multiple Group By's in linq to sql?

Hi how can you do multiple "group by's" in linq to sql? Can you please show me in both linq query syntax and linq method syntax. Thanks Edit. I am talking about multiple parameters say grouping by "sex" and "age". Also I forgot to mention how would I say add up all the ages before I group them. If i had this example how would I d...

Select multiple coulmns with linq method syntax

Hi How do I select multiple columns in linq to sql method syntax? I only know how to select one column but not multiple columns. Like if I had a this table ProductId ProductName ProductQty ProductNumber How could I select productName and ProductQty but not ProductNumber or ProductId in linq to sql method syntax? ...

Serializing Linq2Sql over Wcf - bug or misunderstanding?

Working with Linq2Sql as a driver for a Wcf Service. Lets go bottom up.... Down at the bottom, we have the method that hits Linq2Sql... public virtual void UpdateCmsDealer(CmsDealer currentCmsDealer) { this.Context.CmsDealers.Attach(currentCmsDealer, this.ChangeSet.GetOriginal(currentCmsDealer)); } That gets used b...

How to handle nested datacontext in the BL?

public class TestBL { public static void AddFolder(string folderName) { using (var ts = new TransactionScope()) { using (var dc = new TestDataContext()) { var folder = new Folder { FolderName = folderName }; dc.Folders.InsertOnSubmit(folder); ...

What is the Future of Linq to SQL

Ive been searching for Linq tutorials online and came across some articles saying that linq may go away? What is your take on this? Will microsoft really do away with linq ...

Can I use nested DataContexts in Linq TO Sql?

Would creating another datacontext in the GetData3() method lead to problems? public void SetoFDataMethods() { using (DataContext DC= new DataContext()) { var d1=DC.GetData1(); var d2=DC.GetData2(); var d3=DC.GetData3(); display(d3); } } public result GetData3() { If (c...

Linq to SQL Records where child ID in list

I have a site where I have a database of persons and each person can have multiple intrests which is handled through a one to many relationship between a persons table and an interests table. On the site I want to have a serach where you can have a multiple select box of interests and the user can pick as many as they want. What I want t...

C#: Add data to an SQLMetal generated database class?

I used SQLMetal to generate a code file representing my database, and i can't figure out how to add entries to the database from the SQLMetal generated classes. How do i do this? do i just add to the various properties or something? ...

How to write the following in Linq or Sql

Hi, Appreciate if I can get some help writing a LINQ that will get ALL FIELDS from table A, and those fields for which profile 1 has a value in table AB, show the value, otherwise if profile 1 has no entry in table AB, then show value as null. Table A AID Field ----------- 1 OneField 2 TwoField 3 ThreeField Table ...

Develop for SQL Server Standard using SQL Server Express?

I'm working on a web service project, and I'm coding at home, where I have SQL Express 2008 installed, but the app needs to interface with an SQL Server Standard. I've never done the transition before, and I haven't been able to find any resources on the subject - plenty of stuff about upgrading, but nothing about how to deploy. For ins...

System.Data.SqlClient.SqlException: Invalid object name 'dbo.Projects'.

My MVC app is returning SqlExceptions when trying to access any table in my database. Exception Details: System.Data.SqlClient.SqlException: Invalid object name 'dbo.Projects'. My app us linq for the data layer. If I use an old dll it works fine, (so doesn't seem to be a problem with the DB) just this latest app dll that I've uploaded...

Dynamic query with linq to IDictionary<string, object>?

This question is similar to this question but not quite the same. Can I make a dynamic query on a linq-to-sql data context and have the result return as an IDictionary<string, object> where the key is the name of the column? A bit like so (doesn't compile, but illustrates the intention) IDictionary<string, object> data = new Dictionar...

Why Linq can't translate expression/treat as local expression and throws an exception?

I asked a question here about an Linq error that results from mixing Linq-To-SQL with C# code. In brief, the compiler gets confused and doesn't realize that you are intending to call a local function on the resultset after it's come back from the database. The answer I accepted was to use AsEnumerable() on the result set, thus forcing ...

Optimizing Stored Procedures so they will be processed properly by Linq2SQL

Where I work it is a requirement for us to go through stored procedures as a mechanism to access our data through code. I am using LINQ2SQL to minimize this pain so that I can work with objects instead of ADO.NET directly. I have a situation Linq2SQL is consuming one of my stored procedures an generating code where the return type from...

Why isn't DataContractJsonSerializer serializing my Id property?

I'm using LINQ-to-SQL for CRUD functionality, and DataContractJsonSerializer to serialize the object to JSON. I am also using ASP.NET MVC's data binding to post values to an MVC action that does the inserting. The problem is that it will serialize all of the properties except the Id property. I've got the model set up as so: [Serializab...

How to determine if a IQueryable expression needs additional processing besides the standard LINQ to SQL translation to Transact SQL (and possible work arounds)

I’ve two issues that I was hoping for some insight on and/or some appropriate links or Google terms to use to find more information on as I’m not finding anything. It boils down to the fact that I would like to find out when/how an IQueryable expression that is going to be executed determines that some of the expression result needs to ...

Linq to SQL: Select categories that have no subcategories

I need to grab all categories that don't have subcategories 1 ^--1.1 ^--1.2 ^--1.2.3 2 ^--2.1 3 In this example I would want to get [1.1], [1.2.3], [2.1] and [3]. My Categories table looks like this: CategoryID | CategoryName | ParentID I figure I should be selecting all the categories where it's CategoryID isn't used in an...

The query results cannot be enumerated more than once?

Hi, I'm using LINQ to SQL to get a search result of a FullTextSearch stored procedure in Sql server 2008. I dragged the procedure from the server explorer to the designer, and got the method created with the appropriate return type and parameters. Now the problem is, I need to get the Count of the result of calling this method, so using ...

Options for code sharing in Linq2SQL expressions

I have a pair of Linq to SQL queries which contain the same complex Where clause, specifically: where ((range.MinimumFrequency <= minFreq && minFreq <= range.MaximumFrequency) || (range.MinimumFrequency <= maxFreq && maxFreq <= range.MaximumFrequency) || (range.MinimumFrequency <= minFreq && maxFreq <= range.MaximumFrequency) || (range...