linq-to-sql

How do you handle Linq to SQL Foreign Key relationships in WPF DataBinding

I have been fighting this issue for some time so today I started a new project and simplified things to the basics. What I want to do is have a listbox, bound to a collection with a detail view of the selected item shown below. It all works fine except the items that refer to other tables simply show the foreign key. I was able to resolv...

Update table using linq to SQL

In my project I have about 10 Database and those 10 databases have 5 tables each. And in those tables I have two tables which almost have similar columns expect one column. Right now I have two separate methods which update the data in these tables. Is there any way I can combine this two method one. case "A": IEnumerable...

Linq-to-SQL Design question!

What if you need to create POCO objects from a dbml file? Do you use a generator and who? You write the POCO's manually? Say you like to make your objects Persistent Ignorant and share to clients, then create a DAO pattern for the communication between Client - DAO - L2S Objects, this is a question for disconnected design using Linq 2 SQ...

'CompanyName.Foo' is a 'namespace' but is used like a 'type'

Restatement of the question I'm resurrecting this question because I just ran into this error again today, and I'm still utterly confused why the C# compiler bothers to check for collisions between namespaces and types in contexts where it makes no sense for a namespace to exist. If I have... public Foo MyFoo { get; set; } ...why wo...

LINQPad - Log Secondary DataContext to "SQL" Tab

Its easy enough to instantiate multiple DataContexts in LINQPad. Is there any way to set these instances to Log to the "SQL" Tab of the results pane? Setting myDataContext.Log = this.Log doesn't work. ...

ASP.NET MVC 2 LINQ-to-SQL generated classes and Model Validation

Hi, I just want to make sure I understand correctly the best practices for ASP.NET MVC2 with LINQ-TO-SQL. Please correct me if I am wrong at any of the following points: LINQ TO SQL generates classes for you, based on your tables The generated classes are Models Those are the models we are supposed to use in the Views If we want to a...

How do I select the most recent entity of its type in a related entity list in T-SQL or Linq to Sql?

I have a table full of Actions. Each Action is done by a certain User at a certain DateTime. So it has 4 fields: Id, UserId, ActionId, and ActionDate. At first, I was just reporting the top 10 most recent Actions like this: (from a in db.Action orderby a.ActionDate descending select a).Take(10); That is simple and it works. But the ...

Modifying existing AssociateWith<> in Linq-to-Sql

I have some linq-to-sql where we use AssociateWith<> to limit some of the records to only those for a particular user. I might -in some cases- want to limit those records to a specific date too. Once I have created my option.AssociateWith(....), can I modify it? If so, how? thanks! ...

LINQ query result concatenated

Wondering if I can conditionally concatenate LINQ query results from 4 different fields in a table, which are flags into 1 string for each record, so it would be something like this: dbContext.CONTACT_LOGs.Select( e => new (e => new ContactLog { rec1 = e.Recommend1 ? "1 is recommended...

Which SQL Query is Better?

Is this SQL query statement: SELECT p.id, p.[name], SUM(ps.sales_amount) AS GROSS_SALES FROM products p LEFT OUTER JOIN product_sales ps ON p.id = ps.product_id GROUP BY p.id, p.[name] better than: SELECT SUM([t2].[value]) AS [SalesAmount], [t2].[id] AS [ProductId], [t2].[name] AS [ProductName] FROM ( SELECT ( SELECT SU...

Solution for category tree with less query?

Basically, the Model is like this: ---------------------------------- | CAT_ID | CAT_NAME | CAT_PARENT | ---------------------------------- which make this a recursive relationship. But how should we use this model in our Asp.net mvc web application with least amount of query. My temporary solution is pass the object in to the functi...

In Linq to SQL is it better return multiple results sets at once or call the DB using multiple stored procedures?

I am creating a very data intensive, high volume web site. Every aspect of the website is driven by interactions with the MSSQL DB that I am using. On one page there are 10-12 different resultsets that I need to utilize in my page. So I need to know the best practice when it comes to using Linq-to-SQL and multiple results sets with a ...

LinqToSQL Error : Operation is not valid due to the current state of the object

Hi guys, during an update command I was received the following error: Operation is not valid due to the current state of the object I had tried to remove one column from the update command and it works fine. This column is a FK that is similar to the other FK that works fine. Any idea? tnx this is the code that execute the update: ...

Linq to SQL: Using int? as a parameter in a query....

So I have a query that looks something like this: var clams = from clam in Clams where clam.ClamTypeID == 143 && clam.ParentClamID == null select clam; Nothing too crazy, returns the results that I need. But when I have it in a function where I'm passing in the possible null value as a int? I...

Combining Linq-to-SQL and Linq-to-XML

Is it possible to combine Linq-to-SQL and Linq-to-XML if a column of a table is XML? ...

linq to sql syntax different but should get the same results

I was playing around with expression trees and various Linq syntax. I wrote the following: using (NorthwindDataContext DB = new NorthwindDataContext()) { DataLoadOptions dlo = new DataLoadOptions(); // Version 1 dlo.AssociateWith<Customer>(c => c.Orders.Where(o => o.OrderID < 10700).Select(o...

LINQ to Stored XML

Does anybody know the status of this? ...

Update table using Linq and Extension Method

Hi When I try to update table using following code I get error message "Cannot create an instance of the variable type 'T' because it does not have the new() constraint" How Can I create a new instance and update data in database. IEnumerable<BookData> bookData = GetBookData(...); BookDataContext bookDB = new BookDataContext ...

Dynamic Linq 2 Sql using Expressions Trees raising exception "Binary Operator LessThan not defined for System.String and System.String"

Hi, I'm trying to write a dynamic Linq 2 Sql query using Expressions trees but I'm getting a exception telling me that the LessThan and GreaterThan operators are not defined for System.String and System.String, which i find odd, is that true? or am I doing something wrong? Expression<Func<SomeDataContextType, string>> codeSelectorExpres...

schema between local and remote servers.

I have an ASP.NET MVC application that I wrote using LINQ to communicate with the database - everything works fine, but I use MS-SQL Express server on my local machine for building it. When it is ready, I publish it to the live box in a folder for testing. That works fine, too. But the server uses MS-SQL 2005 full - which isn't a probl...