linq-to-sql

Using LINQ to SQL in ASP.NET MVC2 project

Well I am new to this ORM stuff. We have to create a large project. I read about LINQ to SQL. will it be appropriate to use it in the project of high risk. i found no problem with it personally but the thing is that there will be no going back once started.So i need some feedback from the ORM gurus here at the MSDN. Will entity framewor...

Parallelizing L2S Entity Retrieval

Assuming a typical domain entity approach with SQL Server and a dbml/L2S DAL with a logic layer on top of that: In situations where lazy loading is not an option, I have settled on a convention where getting a list of entities does not also get each item's child entities (no loading), but getting a single entity does (eager loading). ...

Using Linq to SQL change events with attribute-based mapping

I'm writing a new ASP.NET MVC2 application using Linq to SQL. This application depends on an existing SQL database. I am using attribute-based mapping to map my database fields to my Linq to SQL entities. I also need to make use of Linq to SQL's On[Property]Changed methods so I can perform change-auditing of database tables within my a...

Cannot update a single field using Linq to Sql

I am having a hard time attempting to update a single field without having to retrieve the whole record prior to saving. For example, in my web application I have an in place editor for the Name and Description fields of an object. Once you edit either field, it sends the new field (with the object's ID value) to the web server. What ...

ASP.NET MVC/LINQ: What's the proper way to iterate through a Linq.EntitySet in a View?

OK so I have a strongly-typed Customer "Details" view that takes a Customer object Model. I am using LINQ to SQL and every Customer can have multiple (parking) Spaces. This is a FK relationship in the database so my LINQ-generated Customer model has a "Spaces" collection. Great! Here is a code snippet from my CustomerRepository where ...

Passing a WHERE clause for a Linq-to-Sql query as a parameter

Hi all This is probably pushing the boundaries of Linq-to-Sql a bit but given how versatile it has been so far I thought I'd ask. I have 3 queries that are selecting identical information and only differ in the where clause, now I know I can pass a delegate in but this only allows me to filter the results already returned, but I want t...

Linq To Sql: Compiled Queries and Extension Methods

Hi community, I'm interessted, how does Linq2Sql handles a compiled query, that returns IQueryable. If I call an extension method based on a compiled query like "GetEntitiesCompiled().Count()" or "GetEntitiesCompiled().Take(x)". What does Linq2Sql do in the background? This would be very bad, so in this situation I should write a compi...

linq to sql flaws

has linq to sql has any major and known flaw? ...

Linq Error generating SelectListItems

This is a weird one that i can't figure out. My method has one paramemer a nullable int int? selectedtitleid This is the Linq code: var titles = from t in dc.Titles select new SelectListItem { Text = t.Title1, Value = t.TitleID.ToString(), Selected = (t.Title...

How to use IN operator in Linq?

Query: Select * from pu_Products where Part_Number in ('031832','027861', '028020', '033378') and User_Id = 50 and Is_Deleted = 0 The above mentioned query is in SQL and i need the query might be converted into Linq. Is there any option using the "IN" operator in Linq?. can you convert above mentioned query into Linq? ...

Composable FLinq expressions

When doing linq-to-sql in c#, you could do something like this: var data = context.MyTable.Where(x => x.Parameter > 10); var q1 = data.Take(10); var q2 = data.Take(3); q1.ToArray(); q2.ToArray(); This would generate 2 separate SQL queries, one with TOP 10, and the other with TOP 3. In playing around with Flinq, I see that: le...

Inserting data using Linq

I have a linq query to insert data in table. but its not working. I saw some example on internet tried to do like that but doesn't seems to work. Tablename: login has 3 columns userid, username and password. I set userid as autoincrementing in database. So I have to insert only username and password everytime.Here's my code. linq_testD...

How to use PredicateBuilder with nested OR conditionals in Linq

I've been very happily using PredicateBuilder but until now have only used it for queries with only either concatenated AND statements or OR statements. Now for the first time I need a pair of OR statements nested along with a some AND statements like this: select x from Table1 where a = 1 AND b = 2 AND (z = 1 OR y = 2) Using the docu...

A better UPDATE method in LINQ to SQL

The below is a typical, for me, Update method in L2S. I am still fairly new to a lot of this(L2S & business app development) but this just FEELs wrong. Like there MUST be a smarter way of doing this. Unfortunately, I am having trouble visualizing it and am hoping someone can provide an example or point me in the right direction. To t...

search with list of comma seperated values using linq to sql

What is the best way to handle the following database search scenario using asp.net mvc, sql server and linq to sql? I have a simple search for people, by their first name and last name. Based on the results, I would like to dynamically filter the results base on the people's City and Business. This could be multiple cities or busin...

LinqtoSql Pre-compile Query problem with Count() on a group by

Have a LinqtoSql query that I now want to precompile. var unorderedc = from insp in sq.Inspections where insp.TestTimeStamp > dStartTime && insp.TestTimeStamp < dEndTime && insp.Model == "EP" && insp.TestResults != "P" group insp by new { insp.TestResults, insp.FailStep } into grp ...

Delete query in Linq

I have this simple code but it shows error. I dont know where I am going wrong. I shows error in last line.."DeleteOnSubmit" linq_testDataContext db = new linq_testDataContext(); var remove = from aremove in db.logins where aremove.username == userNameString && aremove.Password == pwdString select aremove; db.logins.D...

SQL Like keyword in Dynamic Linq

Hi fellow programmer I want to use SQL's Like keyword in dynamic LINQ. The query that I want to make is like this select * from table_a where column_a like '%search%' Where the column_a can be dynamically changed to other column etc In this dynamic LINQ var result = db.table_a.Where( a=> (a.column_a.Contains("search")) ); But th...

Why is TransactionScope using a distributed transaction when I am only using LinqToSql and Ado.Net

We are having problems on one machine, with the error message: "MSDTC on server XXX is unavailable." The code is using a TransactionScope to wrap some LingToSql database code; there is also some raw Ado.net inside of the transaction. As only a single sql database (2005) is being accessed, why is a distributed transaction being ...

How to create custom get and set methods for Linq2SQL object

I have some objects which have been created automatically by linq2SQL. I would like to write some code which should be run whenever the properties on these objects are read or changed. Can I use typical get { //code } and set {//code } in my partial class file to add this functionality? Currently I get an error about this member alread...