linq-to-sql

Split function in where clause

hello friends I am using following query in linq In product table following type of data are stored abc-def bcd=fgh abc-xyz var query=from prod in db.Product join cat in db.category on prod.categoryId=cat.categoryID where prod.productName.split('-')[0]=="abc" but in that query it product annoumous problem Please give some suggestio...

Which is the most suitable method for Data Access in Silverlight 3?

We are planning to move to Silverlight 3 for application development because we want to take advantage of more flexible UIs and easier deployment. We have previously used Winforms with ADO.Net and SQL Server for data driven applications. I've briefly looked at some of the options for data access with silverlight such as Entity Framework...

LINQ Searching Only Allowing Equivalency

Hi folks, I'm trying to filter a set of records based on a sub-object's criteria. This compiles ok recordList = recordList.Where(r => r.Areas.Where(a => a.Area == "Z").Count() > 0); but this doesn't recordList = recordList.Where(r => r.Areas.Where(a => a.Area <= "Z").Count() > 0); giving these errors Cannot convert lambda expressi...

What makes a LINQ Association an EntitySet<table>?

I just finished using Linq to Sql to map our existing Database structure for use in a Thick Client app. While writing some Linq Methods to replace some Stored Procedures I noticed that sometimes I could do tblOne.tblTwo.MyDesiredField. I learned that there needed to be an association in the dbml for that to work. Well mine was missi...

Innerjoin in Linq-to-sql for this in asp.net mvc?

I use asp.net mvc... How to write an inner join in linq-to-sql for this sql query select M.Mat_id,M.Mat_Name,T.Name as Measurement,M.Mat_Type as Description from Material as M inner join MeasurementTypes as T on M.MeasurementTypeId = T.Id where M.Is_Deleted=0 And my repository class has this, public class ConstructionReposit...

How to get rid of this error in asp.net-mvc?

I am using Linq-to-sql as an ORM. I wrote this innerjoin public IQueryable<Material> FindAllMaterials() { var materials=from m in db.Materials join Mt in db.MeasurementTypes on m.MeasurementTypeId equals Mt.Id select new { m.Mat_id, m.Mat_Name, Mt.Name, ...

How to I define/change the mappings for Linq To Sql in code.

I wish to be able to change the table a class is mapped to at run time, I can’t do this if all the mappings are defined with attributes. Therefore is there a way to define the mappings at runtime in code. (I would rather not have to maintain xml mapping files.) Say I have two tables: OldData NewData and sometimes I wished to que...

How do you Count/Sum within a Lambda expression

I need to convert the following TSQL query into a Lambda and am stuck on Count and Sum. I know I can Add .Count() and .Sum at the end of the expression - but how do I get the value as part of the expression? T-SQL: select b.pk, b.CreateTime, b.StartTime, b.endTime, count(a.rowid) as total, sum(case when ItemStatus = 'success' then 1...

Should I invest time in learning about OR\M or LINQ?

I'm a .NET web developer primarily who occasionally writes console applications to mine data, cleanup tasks, etc. Most of what I do winds up involving a database which I currently design via sql server management studio, using stored procedures, and query analyzer. I also create a lot of web services which are consumed via AJAX applica...

LLBLGen: Copy table from one database to another

I have two databases (SQL Server 2005) with the same table schemes. I need to copy data from source table to destination with some modification of data along the way. And if destination table already contains some data, then rows from source table should not override, but be added to the destination table. In our project we use LLBLGen...

Does a TransactionScope that exists only to select data require a call to Complete()

In order to select data from part of an application that isn't affected by dirty data, I create a TransactionScope that specifies a ReadUncommitted IsolationLevel as per the suggestion from Hanselman here. My question is, do I still need to execute the oTS.Complete() call at the end of the using block even if this transaction scope was ...

Linq. Help me tune this!

I have a linq query that is causing some timeout issues. Basically, I have a query that is returning the top 100 results from a table that has approximately 500,000 records. Here is the query: using (var dc = CreateContext()) { var accounts = string.IsNullOrEmpty(searchText) ? dc.Genealog...

Linq Group on a multi-level object with select statement

Hi, I've got 3 dataset objects that are nested with each other using entity set objects. I am selecting the data like this var newList = from s in MainTable from a in s.SubTable1 where a.ColumnX = "value" from b in a.Detail where b.Name = "searchValue" select new { ID = s.ID, Company = a.CompanyName, Name = b.Name, Date = s.DueDate Col...

Updating an object with L2S with ASP.NET MVC

Is there an easier way to update an object with L2S other then doing it property by property? This is what I am doing now: Public ActionResult Edit(Object obj) { var objToUpdate = _repository.Single<Object>(o => o.id = obj.id); objToUpdate.Prop1 = obj.Prob1; objToUpdate.Prop2 = obj.Prop2; ... _repository.SubmitCh...

Can't get Sum() working in Northwind example

Hi, The following code is generating a runtime error and I have no idea why. from o in Orders group o by o.Employee into employeeOrders select new { employeeOrders.Key.EmployeeID, employeeOrders.Key.FirstName, Orders = from eord in employeeOrders orderby eord.OrderID select new { eord.Or...

Linq To Sql - SQL Default Constraint Problem

I have a USER table in database. The table has a RegistrationDate column which has a default constraint as GETDATE(). When using LINQ, I don't provide any data for RegistrationDate column to make it default. But SQL Server raises error. I think LINQ tries to insert NULL into the column. How can I make LINQ not to try to insert in the c...

ASP.NET MVC 2: Linq to SQL entity w/ ForeignKey relationship and Default ModelBinder strangeness

Once again I'm having trouble with Linq to Sql and the MVC Model Binder. I have Linq to Sql generated classes, to illustrate them they look similar to this: public class Client { public int ClientID { get; set; } public string Name { get; set; } } public class Site { public int SiteID { get; set; } public string Name {...

Whats the proper way to do explicit transactions with linq to sql?

I have some scenarios where I need to have multiple calls to .SubmitChanges() on a datacontext, but I want to explicitly control the transaction myself to make it atomic. For a while I have been doing this by creating a connection, creating a transaction on that connection, then creating the datacontext and passing it both. Lets assume f...

Property changing null whilst updating a value.

i am retreiveing the Data object through a class which is partial class in linq to sql. i am using the same object model to update the changes. but proprertychanging is always null for this object. An anonoymous type has been converted into strong object type. This strong type is updated again. Can anyone explain the reason for th...

Creating LINQ to SQL for counting a parameter

I'm trying to translate a sql query into LINQ to SQL. I keep getting an error "sequence operators not supported for type 'system.string'" If I take out the distinct count part, it works. Is it not because I'm using the GROUP BY? SELECT COUNT(EpaValue) AS [Leak Count], Location, EpaValue AS [Leak Desc.] FROM ChartMes.dbo.Re...