linq-to-sql

Foreign key problem with Doddle Audit.

I've just started playing with Matt Hidinger's great looking Doddle Audit, which provides DataContext located automatic auditing of any changes to LINQ to SQL entities. It works great for single entities, but also has a feature for associations, e.g. where Order and Order Items are related, changes to an Order Item reflect under changes...

How to write this linq query to avoid too many query?

I have two table Company and Employee. And there relation is Company(one) - Employee(many). And I want to concatenate all the Employees' name to a string and output. I know I can write such a query : String names = ""; foreach(var emp in Company.Employee) { names += emp.name; } But If I use this mean, I would l...

Merging changes in LINQ to SQL entities.

I have the following code that updates the JobCard object returned from a strongly typed view. However, calling GetModifiedMembers with the JobCard entity returns every property of JobCard, with CurrentValue and OriginalValue both set to the current value. public int Update(BusinessObjects.JobCard model) { Poynting.Inst...

LINQ to SQL - How do stored procedures interact with unsubmited datacontext changes?

Someone here asked: "Linq-To-Sql enables calling SPs. If this SP executes an update/delete/insert, do I need to SubmitChanges() after it?" And the answer was: "No you don't. The code will work. Submit changes is only concerned with modified LINQ to SQL objects and not stored procs." I would just like to clarify: (Please excuse me, I...

c#.net post then write to sql db

Hi, I am new to c#/.net and just switched over to it from classic asp(yesterday). I am trying something very basic to begin with. I have a static form with about 20 questions (texts/textarea/checkbox/dropdown/radio) and it posts to a post page with a submit button. I need the post page to gather the answered questions and write them to...

Aggregate or join strings in linq to sql query (SQL Server)

Given a table like ID | Name | City 1 | X | Y 2 | Z | Y 3 | W | K I want to produce a result like ID | Description 1 | Y (X, Z) 3 | K (W) I tried something like From C In Clients Group C By C.ID, C.City _ Into G = Group Select New With {.ID = ID, .Description = City & _ " (" & (From C In Clients Select C.Name).Aggreg...

Group by Week of year (Week number) in Linq to SQL

In regular SQL i could do something like SELECT * From T GROUP BY DATEPART(wk, T.Date) How can i do that in Linq to SQL ? The following don't work From F In DB.T Group R By DatePart(DateInterval.WeekOfYear, F.Date) Also don't work: From F In DB.T Group R By (F.Date.DayOfYear / 7) ...

Can you help me understand this C# code?

I'm reading Pro ASP.Net MVC2 and I've gotten to a point where nothing is explained well enough. For example, the following tells me to create this C# code manually: Implementing the Auctions Domain Model With LINQ to SQL, you can set up mappings between C# classes and an implied database schema either by decorating the classes wi...

AssociateWith Filtering a Linq2Sql context with

I am using Linq to SQL and I have a root table that hold languages used by my application All other tables have a foreign key to this table. My idea was to filter the context according to the language So I used this code DataLoadOptions options = new DataLoadOptions(); options.AssociateWith< Language>(l => l.ID == 1); W...

How can I use current user (default membership) as a data fied in DetailsView?

Hi, I am new to asp.net. I have a details view control on my page. I use linq to sql. My details view is an admin panel for data entry page. So some members will enter some news to my database. I want to use "Writer" Data Field to be filled automaticly with the current logged user. How can I do that? Thanks ...

ASP.NET MVC/LINQ - retreiving tables and number of connections

Still extremely new to the whole MVC/LINQ thing. I'm in the processes off building a blog, and I need to build a table for the posts, and within each post build a table for the comments of that post. To build the tables, I'm doing something like: postsTable = (new DataContext(connectionString)).GetTable<Post>(); Unfortunately for eac...

MVC2 Multiple Model definition from linq to sql class VB.net

I call upon the VB ninjas out there. Here's my situation. I need to eventually be able to pass multiple models to a view. Currently I have a linq to sql class that, of course, has a bunch of generated model definitions. I need to make a model that implements multiple models. I somewhat understand how to do this in C#, but this project is...

Linq - Group by multiple tables.

Using Linq to Sql how do i group the following 2 tables. Orders Table: CustomerID | Name |Date 1 | order1 | 2010-01-01 2 | order2 | 2010-01-01 2 | order3 | 2010-04-01 Calls Table: CustomerID | Name |Date 1 | call1 | 2010-01-01 3 | call2 | 2010-06-01 2 ...

LINQ query to delete particular record

I need to delete a record from the table For one CategoryId I will have several serviceTypes.. Ex: CategoryId = 123 Service types related to this is 1 2 3 4 5 I need a query to delete servicetype 3 to CategoryId 123.. My method will be I will pass Deleterecord(CategoryId,ServiceTypeId); ...

How can I databind ASP.Net Menu Control using LINQ to SQL

I'm new to LINQ and I have an ASP.Net Menu control, I want that to be generated dynamically using LINQ complete with Parent and Child nodes. Hope someoene could help. ...

LINQ to SQL grouping multiple columns with a distinct row

I have the following table structure. I want to select distinct CustomerId and CustomerName, TotalCost. Here's the table structure and column data type. LogId (int) CustomerId (string) CustomerName (string) Cost (int) Logid / CustomerId / CustomerName / Cost 1 2031 John Steward 20 2 2035 Mary Joe 10 3 2034 Robert Tuck ...

Implementing (Date - Time Delta) in SQL Server 2008

I want to be able to send reminders for appointments. Given the tables: - Appointment ID (PK) Start - Reminder AppointmentID (FK) MinutesBeforeAppointmentToSendReminder -- only need minute resolution I would like to select reminder times: select ..., DateAdd(minutes, -Reminder.MinutesBeforeAppointmentToSendReminder, Appoint...

LINQ to SQL: SubmitChanges() does not work?

Here's my code var bt = new BachtuocvnDataContext(); var matchedTeams = (from lt in bt.Bet_Leagues_Teams where lt.LeagueID == leagueID select (lt)).Single(); matchedTeams.TeamID = teamID; bt.SubmitChanges(ConflictMode.ContinueOnConflict); It does not upd...

Using a member access lambda expression to parametrise a LINQ to SQL predicate

I have a query that needs to be reused all over the place and I need to vary which property/column gets used for a join. What I'd like to be able to do is something like: query = RestrictByProp(query, x=>x.ID); An extremely simplified RestrictByProp() could be*: private static IQueryable<Role> RestrictByProp(IQueryable<Role> query,...

How do I delete all child elements using linq to sql?

Is there an easy way to delete all child records for an item using Linq to sql? ...