linq

Problems with LINQ

Hi everyone, I recently have some issues with LINQ2SQL, first of these as that I cant use CRUD methods I dont know whats the matter with LINQ ORM, I cant Update or Delete some entity already mapped in .dbml so I always fix this with drop and renew the .dbml , but now stills not working. Problem : Entity is not associate already Sys...

LINQ query operator for log table

I am trying to find the corerct LINQ to SQL query operator and predicate combo that can operate on an audit table. Imagine a table called Setting that has three columns : rowID, DefID, and Value. I want to be able to check that every DefID ( in this case all definition 1 through 3 ) has at least one row which has a value set to true. ...

How to deal with a flaw in System.Data.DataTableExtensions.CopyToDataTable()

Hey guys, so I've come across something which is perhaps a flaw in the Extension method .CopyToDataTable. This method is used by Importing (in VB.NET) System.Data.DataTableExtensions and then calling the method against an IEnumerable. You would do this if you want to filter a Datatable using LINQ, and then restore the DataTable at the e...

Find or Create Element in LINQ-to-XML

I want to set the value/children of an element that may or may not already exist. If the element doesn't exist, I want to have it automagically created for me. This way, my code only has to worry about the contents of the element... not whether or not it already exists. (By the time I'm done with it, it's guaranteed to exist). Does th...

How to get the TSQL Query from LINQ DataContext.SubmitChanges()

I'm using Linq to SQL. I have a DataContext against which I am .SubmitChanges()'ing. There is an error inserting the identity field, and I'd like to see the query it's using to insert this identity field. I don't see the query itself within the quickwatch; where can I find it from within the debugger? ...

Linq to SQL: Why am I getting IDENTITY_INSERT errors?

I'm using Linq to SQL. I have a DataContext against which I am .SubmitChanges()'ing. There is an error inserting the identity field: Cannot insert explicit value for identity column in table 'Rigs' when IDENTITY_INSERT is set to OFF. The only identity field is "ID", which has a value of 0. It's defined in the DBML as: [Column(Storage=...

How would you write an Upsert for LINQ to SQL?

So I'd like to write a generic Upsert function for LINQ to SQL and I'm having some trouble conceptualizing how to do it. I'd like it to work something like this: var db = new DataContext(); db.Customers.UpsertOnSubmit(customer); So it would have to be generic in some way and I guess and extension method on Table. I've been able to g...

Adding related records in LINQ

Hi there, Processing an XML file with LINQ to add records into a table in a SQL Server database via a data context. As we are adding records we need to assign the parents in various other tables. Most of the time we can find the existing parent and use it but sometimes we will need to create a new parent. Thought we could do this like...

Workaround for MethodBase.GetCurrentMethod() on Compact Framework 3.5

I want use a Linq IQueryable Toolkit in project on .NET Compact Framework. The Linq capabilities in CF is little bit shapred - i.e.: IQueryable interface is not available. So I've found third party libraries, which implements missing functionality what I need. Now I have problem with missing method "MethodBase.GetCurrentMethod()". There...

Linq to SQL connections

I'm using Linq to SQL for a fairly complicated site, and after go live we've had a number of database timeouts. The first thing I noticed was there are a fairly large number of connections to the database. Coming from an ADO.net background we used to code it so that any site would only use one or two pooled connections, and this resulte...

interface design with Linq2Nibernate and IQuerable

When using Linq2Nibernate is better to make you Repository return a IQuerable? My understanding is that if you use Linq to Nibernate the the query will not "fire" until you call .First() or Single() ect ect. So would it not be best to return IQuerable from all you Interfaces so you can build up\manipulate the expression tree before it ...

linqToSql related table not delay loading properly. Not populating at all.

I have a couple of tables with similar relationship structure to the standard Order, OrderLine tables. When creating a data context, it gives the Order class an OrderLines property that should be populated with OrderLine objects for that particular Order object. Sure, by default it will delay load the stuff in the OrderLine property but ...

LINQ - Return Value From Field With A Max Value if No Rows Found

I have a table like this... ID Description LowThreshold HighThreshold 1 BAD 0.0 .69 2 MEETS .70 .89 3 GOOD .90 2 The object here is to write a LINQ query that will select the right Description based on a given decimal. For instance .75 is between .70 and .89, so it...

LINQ Query to Produce Non-Empty Nested Menu?

To see my problem in action, visit www.apoads.com and hover over the "Local Businesses" menu item. It's a series of nested unordered lists generated from a db call. Go ahead and click on a few of the items underneath "Local Businesses", you'll see that most of the categories are empty (the site is very new). Problem: I only want to sho...

Is linq's let keyword better than its into keyword?

I'm currenly brushing up on linq and am trying to comprehend the difference between the let and using key word. So far the let keyword seems better than the into keyword as far as my understanding goes. The into keyword essentially allows one to continue a query after a projection. (just want to state explicitly that I'm not referring ...

LINQ to SQL inserting large object from .NET

What is the fastest way to get a list object with a count of 100,000 records into SQL using LINQ to SQL? ...

LINQ to SQL - Problem with 1-to-1 association

In the L2S designer I have dropped a table and a view. I tried adding an association between the 2 on their primary keys. This should be a one-to-one relationship, so I set the cardinality property of the association as such. But, when coding I can't access the child property. Any suggestions? EditI just created a view in sql server ...

Learning the Entity Framework

I am interested in learning all about the Entity Framework. I have found these videos. I also have the book Programming Entity Framework, 1st Edition by Julia Lerman. Does anyone have any other recommendations for learning this new technology? ...

can linq update and query atomically?

Hi, I need to get 1000 rows from a database, and at the same time tag them as 'in process'. This way, another thread can not take the same 1000 rows and process them as well. With linq i do something like this: msgs = (from m in database.messages where (m.status == MESSAGESTATUSINIT) select m).Take(1000).ToList(); ide...

Linq: IsNot in Object collection

Dim goodCustObjList As New List(Of CustomerObj) goodCustObjList = DataBLLModule.GetCustomerRecordList(String.Empty) Dim custList = From t In goodCustObjList _ Where t.ID.ToString() IsNot Guid.Empty.ToString() _ Select t I have a list of CustomerObj and if the ID (GUID) is not empty then i want to select t...