linq-to-sql

Problem with Rolling back a linq2sql insert transaction in C#

Hi, i am trying to insert the contents of a CSV file into a database table using linq2SQL. I want to be able to rollback the transaction if ANY of the inserts fail but when i try with this code i get the following error at - db.Transaction.Commit() System.InvalidOperationException was unhandled: This SqlTransaction has completed; it is...

Help needed to create LINQ Summary Line

Hi all I have got the following LINQ query, apologies for the poor variable naming. Dim bla3 = From c In crdc.SRAs _ Where c.acad_period = ReviewCredential.AcadPeriod _ And c.periodID = ReviewCredential.PeriodID _ And c.aos_code = ReviewCredential.AoSCode _ And c.aos_period = ReviewCredential...

Sending Linq to SQL classes over webservice

I have a windows application and a web service. Both have a Linq to SQL mapper with Customer table on them. Same table from the same database, same everything. I tried to send winapp.Customer object to web service but the webserviceReference.MyMethod() accepts webservice.Customer object and doesn't accept winapp.Customer as parameter. Tr...

NLOG to output db.out

I would like to use nLog to output my LINQ to SQL generated SQL to the log file e.g. db.Log = Console.Out reports the generated SQL to the console, http://www.bryanavery.co.uk/post/2009/03/06/Viewing-the-SQL-that-is-generated-from-LINQ-to-SQL.aspx How can I get the log to log to NLOG? ...

LINQ VB how to select records with the max date (highest date)

I know how to do this in C#, but my dev team doesn't use C#... here is the answer in C#: http://stackoverflow.com/questions/470440/linq-how-to-select-only-the-records-with-the-highest-date How do I do this in VB? Essentially, if I knew how to write lambda expressions in VB, I would be set, but the materials I have found are not helpfu...

How do I insert/delete/update in an ordered tree

I have two tables in which I store a tree with ordered levels like this: Table: TreeData --------------- ID (int) (primary key) Data (string) Level (int) (not null) --------------------------------------------- Table: SubTree --------------- parentID (int) (foreign key #1 to TreeData.ID) childID (int) (foreign key #2to TreeData.ID) o...

Caching aggregate results in Linq2SQL

We have a small affiliate program and a simple tool to view affiliate statistics. The Linq for showing the report: from e in linq0 select new { Id = e.Id, Name = e.CompanyName, EnquiryCount = (int?)e.CampaignCodes.Sum(f => f.Enquiries.Count()) ?? 0, EnquiryOrderSum = (int?)e.CampaignCodes.Sum(f => (int?)f.Enquiries.Sum...

Can Entity Framework do what Linq To SQL does?

I'm a bit confused, I have worked with Linq To SQL and gather we can query anything in the dbml or entities e.g: var query = from i in db.mytable select i; But in the Entity Framework (which supposedly Microsoft are replacing Linq To SQL with) how can we do the same thing? Is it even possible? How does it replace Linq To S...

From old DataLayer to LINQ to SQL / Entity Framework

There are a few "should I chose this or that" questions on SO and Google, as well as a lot comparing LINQ2SQL and LINQ2E. I've seen drawbacks, differences, cons, pros, limitations, etc. I cannot say I'm an expert but I'd like to know "what would you do" if you faced this scenario and why. I have to add stuff to an "old" 2.0 app that ha...

Why is the LinqToSql generated Where clause so convoluted?

I receive a daily XML file which I use to update a database with the content. The file is always a complete file, i.e. everything is included whether it is changed or not. I am using Linq2Sql to update the database and I was debating whether to check if anything had changed in each record (most will not change) and only update those whic...

Inconsistency in LinqToSql Update

I am running the following code: if(ven.Source == null)ven.Source = new Source(); ven.name = (string) venue.Element("venueName"); Console.WriteLine("Venue Name: " + ven.name); ven.Source.companyId = 1; ven.Source.sourceReference = (string)venue.Attribute("...

What should I know about working with ADO.Net Data Services? (FAQ)

I've been learning by doing with ADO.Net Data Services (Astoria) for the last couple of months, and while I like the technology the learning has been a real trial. Information that you need to use them effectively is spread over MSDN documentation, articles, blog posts, support forums and of course StackOverflow. This question is a place...

Linq to sql convert IQueryable to Dataset

What is the easiest way to convert an IQueryable object to a dataset? ...

How to identify set of records to be deleted using LinqToSql where not in another set?

I have a daily xml feed which contains all records each day. These need to be processed and loaded to a database i.e. those not included in the feed for day2 which were in day1 feed should be deleted and any differences should cause an update on the database. My current approach is to update each included record with a processed date and...

Load a DataGridView using Linq to SQL

How can I use Linq-To-SQL to load a DataGridView? Would the following work? DCDataContext db = new DCDataContext(); dataGridViewJobs.DataSource = db.jobs.Select(p => p.closeDate <= DateTime.Now); ...

Populating list(of Customers) in LinQ

How do I populate the List(of Customers) in vb.net. I have the CustomersDataContext and I want to populate the customers. Please help Dim _db As New CustomersDataContext Dim _cust As New Customer Dim customers As List(Of customer) = Nothing ...

Linq to SQL - Left Join with > comparison

Hey all, I'm trying to do a left join in linq to sql that has a date1 > date2 comparison in it but can't figure out how. Here's the SQL: select rd.RouteDispatchID, r.RouteNumber, s.ShortDescription, rd.DispatchDate, rd.CreationDate, e.FirstName, e.LastName, count(md.MachineDispatchID) NumMachines, count(mdp.Pi...

LINQ DataContext.SubmitChanges() in C# Reporting "Object reference not set to an instance of an object."

Hi. I think a lot of people have had this issue but I'm not able to fix it or understand why I'm having it. I've been tearing hair out for a couple of hours now. I'm getting the error, "Object reference not set to an instance of an object." on my datacontext.SubmitChanges() on the SECOND time this method runs (I'm looping through a ...

What pros and cons are there using linq to sql vs creating my own datalayer?

I just started playing with Linq to SQL the other day and was curious if I should use it in up coming projects. I know it will save me tons of developement time. I have seen many similar questions out there on the subject but I have a few more specific questions. Is there anything wrong with inheriting the classes generated in the ...

Key-Entity sync is lost in Linq2sql association when removing child property

I have an association OneToMany from class A to B (A parent property, B child property). The property setter the parent property (B.A = value) has the logic to update the id field in B to keep the entity and the id in sync. That is, whenever I assign a new value to B.A, B.Aid is also automatically updated. But if I happen to remove the...