linq-to-sql

HttpPost Action for updating my model with children from the edit page

I have a simple MVC 2 blog that I'm building as I learn. My edit page has title, body, date, enabled and tags. The tags is where my problem comes in. I have a Tags table and a Posts table and tags are associated to a post through the PostTag table. I have my linq model setup properly and I even have the Add HttpPost action working. My ...

Circular Reference- LINQ to SQL

HI I am using telerik mvc grid with ajax binding <%Html.Telerik().Grid<UserManagement.Models.setupEmployee>() .Name("setupEmployees") .DataBinding(dataBinding => dataBinding //Ajax binding .Ajax() //The action method which will return JSON .Sel...

how to recognize similar words with difference in spelling

I want to filter out duplicate customer names from a database.A single customer may have more that one entry to the system with the same name but with little difference in spelling. So here is an example: A customer named Brook may have three entries to the system with this variations: Brook Berta Bruck Berta Biruk Berta let's assum...

LINQ to SQL cross apply

I would like to create a query with a cross apply into a user defined table value funtion in LINQ. The SQL would be really rather simple as below: SELECT * FROM MyTable mt CROSS APPLY MyTVF(mt.id) This post gives an example of a LINQ query that results in generated sql that contains both a cross apply and an outer apply but only for ...

Group By and Sum clauses in LINQ

I've written a simple linq query as follows: var query = from c in context.ViewDeliveryClientActualStatus join b in context.Booking on c.Booking equals b.Id join bg in context.BookingGoods on c.Booking equals bg.BookingId select new { c, b, bg }; I have filtered the previous query with a number of p...

Dynamic data website with 1 datacontext but multiple connection strings

Is there any way to change the connection string at runtime when working with the Dynamic Data framework and LINQ. There seems to be no way to register multiple Models (with a single shared DataContext) at runtime, I just get an exception saying the specified DataContext type has already been registered. I have tried using multiple mod...

Linq to SQL / C#: How to Order By using property in cross reference table with lambda expressions

I am trying to order a list of products based on the zindex property of the cross reference table with the category table (in this case called 'Chassis'), but I get the following error: Cannot order by type 'System.Collections.Generic.IEnumerable`1[System.Int32]'. The following is the method I am using: public IQueryable<E_Product> Pr...

Creating Database Mocks in ASP.NET MVC using Data from Existing Database

I have an existing ASP.NET MVC application with some sample data in the SQL Server database, which is working fine.. Assuming I have all of the necessary repositories and IOC in place, is there a tool that will extract the data from a group of tables, and "freeze-dry" it into a mock object (perhaps using an XML file to store the data)...

How can I optimise this LINQ query to only execute a single SQL command?

I am using Linq-To-Sql to populate my business layer. Here is a snippet of a query I am working on: fund.FundEntities = fundGroup.tFunds .Select(fe => { var fundEntity = new FundEntity() { BankAccount = null, CloseDate = fe.closeDate ?? new DateTime(), Commitment = fe.commitmen...

StoredProcedure returning multiple resultset Sql To Linq using designer

I want to get multiple resultsets from a storedProc using sql to linq. I was not able to generate it from designer so I wrote below code in designer.cs file. But whenever I add something to designer, it refreshes the designer with the markup in .dbml file and hence it removes the below code every time I add something. I have to copy it e...

Help with Linq to sql query

In the following code, value is a string with comma separated values each of which is a type name. I want to get the entities which have been linked with any of these types or having one of these types in their description. I have written the following linq to sql servery and I am always getting 0 when there certainly entities with these...

Linq to sql and join problem

I have 3 tables: USER ===== USER_ID(PK) FISRT_NAME LAST_NAME ... ROLES ====== ROLE_ID (PK) NAME USER_ROLES ========== USER_ID(PK, FK) ROLE_ID(PK, FK) I want to extract all user data and all his roles (comma separated) into single row. Sometging like this: 1 | John | Smith | Power user, Administrator 2 | John | Doe | Guest I don...

How to generate SQL COUNT(*) OVER (PARTITION BY {ColumnName}) in LINQ-to-SQL?

Is it possible to generate the following SQL query by using LINQ-to-SQL query expression or method chains which is defer-executable? Data Structure Select Distinct ClassRoomTitle, Count(*) Over(Partition By ClassRoomNo) As [No Sessions Per Room], TeacherName, Count(*) Over(Partiti...

C#: LINQ to SQL Tutorial on youtube.com - Bindings Issue

I don't know if anyone has watched the "Visual Studio 2008, Linq to SQL, C#, and WPF" 21 part tutorial on youtube.com, but I was going through the tutorial and got to the part that I added a datagrid to my WPF. I have SQL Express where I had manually created a database with tables. In the program we created a database connection to th...

LINQ Query Returns List of Lists

I have a query: from m in dc.ReportingMonths where m.Month.Value == month select (from k in m.KPI_Actives where k.DateActive.Year == year select (from r in dc.ReportingViews where r.KPIID == k.KPIID select r) ); Obviously, because it is nested LINQ queries - each returning an IQueryable I get a s...

How can i return list looping select to monitor datagrid with linq?

How can i return list from looping select statements with linq. i need list<list<T>> but i dislike this method. how can i do that? public partial class Form1 : Form { public Form1() { InitializeComponent(); } private void Form1_Load(object sender, EventArgs e) { ISt...

How can I use two different databases with Linq to SQL in Linqpad?

I'm starting out with Linq To SQL, fiddling around with Linqpad and I'm trying to duplicate a SQL script which joins on tables in separate databases on the same server (SQL Server 2008). The TSQL query looks approximately like this: using MainDatabase go insert Event_Type(code, description) select distinct t1.code_id, t2.desc from O...

Linq to SQL Performance in .NET 4

I have a simple query running on both .NET 3.5 and .NET 4, something like this: var x = from o in Orders join ot in OrderTypes on o.OrderTypeId equals ot.OrderTypeId where or.OrderTypeName.Contains("sales") select o; var y = x.ToList(); The identical code runs on both .NET 3.5 and .NET 4, connecting to the same...

ASP.NET + Embedded Database + LinqToSQL

So I'm developing a new component that requires a little storage requirement. I don't want to use a full blown SQL Server database instance because it kind of defeats the purpose of this component. The first thing I tried was a Compact SQL Server database, but by default, ASP.NET does throws an exception if you attempt to use Compact SQL...

ASP.NET MVC (MVC2) Best practices when Inserting/Updating Data using Linq to SQL and Repository layers

I'm in a bit of a conundrum here and I'm hoping for some of you Guru's to help fill in the blanks. The situation I'm currently facing is with regards to my "Users" table and my "OpenID" table. My app allows for a user to have multiple OpenID's, so I keep track of them in a separate table. Users ID Username OpenID ID Us...