linq-to-sql

ORM - Does the Database Schema Drive the Entity Composition or Vice-Versa?

We've had quite a bit of discussion among our development group concerning whether the composition of entities should drive the database design, or should the database design drive the composition of the entities. For those who have dealt with this, what has been your philosophy? Of course, not every entity maps 1:1 to a database table....

System.ApplicationException when using LINQ

When inserting data in my database with linq to sql i get this exception on SubmitChanges(), yet everything used to work before: System.ApplicationException: Member AutoSync failure. For members to be Auto-Synced after insert, the type must either have an auto-generated identity, or a key that is not modified by the databas...

"Order By" in LINQ-to-SQL Causes performance issues

I've set out to write a method in my C# application which can return an ordered subset of names from a table containing about 2000 names starting at the 100th name and returning the next 20 names. I'm doing this so I can populate a WPF DataGrid in my UI and do some custom paging. I've been using LINQ to SQL but hit a snag with this lo...

Is there a general rule on what fields in linq to sql to have the UpdateCheck set to never?

I have a field in my dbml file and when I try to update it, it gives me an error saying that the row or data has been changed. I read that a solution would be to change the field's update check to never, but I am unclear on what this actually means. All I have read is that Linq To Sql uses optimistic concurrency for updates and deletes...

Select top on each group using LINQ to SQL?

Hi, I currently have the flowowing object News: NewsID (PK) CategoryID (FK) NewsTitle Category: CategoryID (PK) CatName How can I select the last 5 news for each group using LINQ to SQL? I can't use foreach in this case because it cause multiple query. What should I do to optimize with just one or few query possible? Thank you ...

Linq To Sql: writing a query for a column named with two words

I'm trying to make query in a table that has a column named "First Name" dim info = from md in employees _ where md!first name = "test" How can I use the field "first name" in this query. I've tried \"first name\" and ""first name"" but neither works. ...

Good architecture for 2-tier(client-server) desktop application using linq-to-sql

Hi, Our present architecture - UI,BusinessLayer,DAL(generated linq-to-sql).In the DAL layer, we have added validation logic for entities in partial class. We are directly using entities generated by linq-to-sql in businesslayer(which is bunch of classes - class\form).Also, in these bll classes,we create linq-to-sql queries. I feel we co...

Using Linq to SQL, how do I find min and max of a column in a table?

I want to find the fastest way to get the min and max of a column in a table with a single Linq to SQL roundtrip. So I know this would work in two roundtrips: int min = MyTable.Min(row => row.FavoriteNumber); int max = MyTable.Max(row => row.FavoriteNumber); I know I can use group but I don't have a group by clause, I want to aggrega...

How do i query this complex query in T-SQL / Linq?

Currently I have 2 table [Category] -> PK| CAT_ID -> CAT_PARENT (link to itself | if it's a top parent category then it's 0) [Posts] -> PK | POST_ID -> FK | CAT_ID | CREATE_DATE How do I select top 15 ROWS of Posts in every CAT_PARENT which have multiple child category. So the total Posts in CAT_PARENT and all it's child are only 15. ...

How do I sort a gridview of Linq objects based on a derived field?

Hi all, I have written a page which uses Linq to query the database and bind the resulting IQueryable to a datagrid. I have a partial class which contains extra properties which derive their values based on other values brought in from the database. Sorting works fine on fields that are actually in the database but not for the derived f...

How can I set a value on a Linq object during the query?

Hi all, I have a simple query i.e. var trips = from t in ctx.Trips select t; The problem is that I have an extra property on the Trip object that needs to be assigned, preferably without iterating through the returned IQueryable. Does anyone know how to set the value during the query? (i.e. select t, t.property = "value")...

"Between" in C# Linq?

Dear All, Hi, I need to write this query in LINQ C#. can anyone help me? Select * From Mytable where MyText BETWEEN 'john' AND 'Pear' ...

in LINQ to SQL how would i create an outer left join to the first element of the right table?

Hi, I have two tables Orders and Products where Orders has a ProductID as a forgin key, I would like to select all products, if a product has orders i would like to select the one with the highest distance field. thanks, ...

linq to sql or LLBL

Hi, I am starting big asp.net project but I could not decided LLbl or linq to sql. Can you help me? What is advantage or disadvantage of linq to sql and LLBL? Which one should I use? ...

Some Issues about Rob Conery's repository pattern !

Hi, I'm trying to apply repository pattern as Rob Conery's described on his blog under "MVC Storefront ". But i want to ask about some issues that i had before i apply this Design pattern. Rob made his own "Model" and use some ORM "LinqToSql" to mapp his database and then he used some interfaces and custom Repositories on top of these...

Simple SQL query to LINQ

I have the following query: SELECT FROM tblMailToSend WHERE (DateToSend < @dateToSend OR DateToSend IS NULL) AND DateSent IS NULL @dateToSend is passed in as a param I'm trying to convert this to linq to sql query. I've got: db.MailToSend.Where(m => m.DateToSend == null || m.DateToSend <= dateToSend) .Where(m =>...

get data using junction table with linq-sql confused :$

Im using linq-sql .I have 3 tables. e.g Project, People and a ProjectsPeople(fk's ProjectID and PeopleID) (junction) Table. given a set of peopleIDArray (an array of ints as people ID's) how can i get only Projects that have atleast one of the peopleId's associated with them? i.e there will be atleast one (may be more) record in the ...

DDD: Can I have my persistence layer object implement an interface that uses enum, with implicit conversion to int?

I have a domain interface public interface ITicket { ... TicketWorkflowStatus StatusId{get;set;} // Enum } but the linq-to-sql persistance layer on the database wants to use int, can I change it in the dbml so that the local type is TicketWorkflowStatus? What are my options? ...

Linq Update Query generates Where 0 = 1?

I am setting the Address of a class generated by Linq 2 Sql and when I try to SubmitChanges(), the sql query it generates is: Update Users Set Address = @po Where 0 = 1 --@po: Input VarChar (Size = 15; Prec = 0; Scale = 0) [123 45th Street] I can't figure out why I am getting Where 0 = 1. ...

LINQtoSQL caching question

I have been doing a lot of reading but not coming up with any good answers on LinqToSql caching...I guess the best way to ask my question is to just ask it. I have a jQuery script calling a WCF service based on info that the script is getting from the 1st two cells of each row of a table. Basically its looping through the table, calling...