linq-to-sql

LINQ to sql insert data c#

I have created one function whose purpose is to add data to database (I'm using linq to sql) This is the code I have written public static void Add(string Name, int Quantitty) { DataDataContext Database = new DataDataContext(); tests test = new tests(); test.Name = Name; test.Quantity = (short)Q...

Rewriting NHibernate app in Linq to SQL

Hi, I have an old outdated application written using NHibernate. Now I would like to rewrite it including new functionality and big changes in model. What are main dissadvantages of using Linq to SQL instead of NHibernate ? What are possible problems of using LINQ to SQL, does making DataContext as somethink like singleton can give p...

How do I handle the SqlException "No Records Found" when using LINQ to SQL?

I'm using LINQ to SQL to call sprocs at my company. Normally it works great but on some queries, if nothing is found it will throw a SqlException "No Records Found". How should I handle this case? Here is an example call I would make: /// <summary> /// Gets the pending messages. /// </summary> /// <par...

Why isn't MVC binding my nested collection?

Hello SO, If got a couple of linqTOsql objects that I am trying to edit through a form. First, there's the Stream class: [Table] public class Stream { [HiddenInput(DisplayValue = false)] [Column(IsPrimaryKey = true, IsDbGenerated = true, AutoSync = AutoSync.OnInsert)] public long StreamID { get; set; } /*other propert...

How do you get values from three different tables using linq to sql?

This is quite straightforward: I have three tables: Questions: ID (PK) Body QuestionsAndAnswers: QuesionID AnswerID Answers: ID Body IsCorrect Each has a corresponding Class: [Table] public class Questions { [Column]public int ID; [Column]public string Body; } [Table] public class QuestionsAndAnswers ...

Updating table with new objects without mass delete through LINQ to SQL in C#

I am new to database programming and want some tips on performance / best practices. I am parsing some websites to scrap television episode infos and placing them into an MS SQL 2008 R2 relational database. Lets say i have a table filled with type Episode. When i start a new parsing, i generate a new list of Episodes. The thing is, ...

LINQ to SQL to XML (using XML literals in C#)

Is it possible to use variables like <%=person.LastName %> in XML string this way? XElement letters = new XElement("Letters"); XElement xperson = XElement.Parse("<Table><Row><Cell><Text> <Segment>Dear <%=person.Title%> <%=person.FirstName%> <%=person.LastName%>, </Segment></Text></Cell></Row>..."); foreach (Person person in pers...

Linq To Sql: handle NewID()

hey, im trying to add data to my sqlserver by using Linq To Sql, in the table, the data design to get NEWID() when new row is inserted, but the linq to sql ignore it and the cell in null, thanks! ...

Updating Linq2Sql object gives exception in MVC

Hi I have a asp.net MVC Web Application. I have a database where i have made my model, i use Linq2SQL to build my Business Logic Layer. In my application i have a customer object, when i call my "editCystomer" page i pass in a Customer to populate the textBoxes: [AcceptVerbs(HttpVerbs.Get)] [Authorize] public ViewResult ...

Working with SQL data via entity or LINQ?

Possible Duplicates: Entity Framework vs LINQ to SQL Dump Linq-To-Sql now that Entity Framework 4.0 has been released? What is faster way or better? Using LINQ to SQL or Entity ? ...

Convert SQL query to LINQ

The below is my SQL query and want to be in LINQ. Can anybody help for this? SELECT EmpId,Team,_Year FROM Plan where EmpId in ( select EmpId from master where 2150 in (immediatesupervisor,manager) ) ...

Delete rows direct in the database but it still display in my asp.net mvc website

I'm developing a website using asp.net mvc 2.0 . I'm using LINQ to SQL for my Model. But I have a problem. When I delete rows direct in the database (by using SQL Server Enterprise Manager, or run query in SQL Query Analyzer), my website still display that rows. It seem LINQ to SQL have automatic cached what it fetched before. How can ...

join problem in linq

i have following tables T1 ==== ====== ID Desc ==== ====== 1 t1 2 t2 3 t3 4 t4 T2 ===== ======= ======== ID T1ID PT1ID ===== ====== ========= 1 2 1 2 3 2 In T2 both T1ID and PT1ID are foreign key for T1. In my output...

How to convert this SQL query to LINQ or Lambda expression?

Hi every one, I have the following SQL query: SELECT C.ID, C.Name FROM Category C JOIN Layout L ON C.ID = L.CategoryID JOIN Position P ON L.PositionID LIKE '%' + CAST(P.ID AS VARCHAR) + '%' WHERE P.Code = 'TopMenu' and following data Position: ID Code 1 TopMenu 2 BottomMenu Category ID Name 1 Home 2...

How do you page IGrouping on the grouped items rather than the group

I'm trying to use skip and take on IGrouping but I don't want to page on the grouped key I want to do it on the items that have been grouped. ...

Search - Order By Keywords

Is there any way to do something like this: var keywords = SearchUtilities.FindKeyWords(q); var j = (from p in _dataContext.Jobs orderby p.JobKeywords.Select(jobKeyword => jobKeyword.Keyword) .Intersect(keywords).Count()) .Take(10).AsEnumerable(); The main idea here is to order search results by the co...

Calling a stored procedure using LINQ to SQL with a Custom Entity Class

Hi Am trying to get linq to call a stored procedure. I know this is usually rather simple, but in this case i am using my own Custom Entity Classes and I am at a dead end. the link below will show you how I have my OM setup example does any one know how you can call a stored procedure from your own Custom Entity Class? EDIT: Forg...

Creating LINQ to SQL Record Properties that Point to Foreign Key Fields?

In my LINQ to SQL generated db class, I have a table with a foreign key reference to a field that has useful date information. A query might look something like this: var query = from a in db.TableA join b in TableB on a.FK_B_Id equals b.Id where b.Date.Value <= DateTime.Today select a; ...or more s...

Linq Query Distinct by Name Distinct Throwing Exception

I have a simple query where I want to get the attributes distinct using the value stored in the "Attribute" property. For some reason I always get Distinct operation not supported for this overload error. var nounTypes = from c in query join cna in ics.CatalogNounAttributes on c.CatalogId equals cna.Cat...

Select multiple tables using Linq to SQL

Hi, I'm trying to bind columns from two different tables in to gridview using Linq To Sql Here's the bind: var q = (from o in mail.tblmails join c in mail.tblstaffs on o.staffId equals c.id select new { o, c }); return View(q); and here is where I'm calling the bind in my View. .Columns(columns => { colu...