linq-to-sql

How do I update a table with LINQ-to-SQL without having to delete all the existing records?

Lets say I have a simple table that only contains two columns: MailingListUser - PK ID (int) - FK UserID (int) I have a method called UpdateMailList(IEnumerable<int> userIDs). How do I, in LINQ, make inserts for the userIDs that are present in the passed in parameter but don't exist in the db, delete the ones that are in the...

Linq to SQL Repository Pattern and string ID

Hi I am trying to use a Repository Pattern with Linq To Sql I am using some of the code from here(http://mikehadlow.blogspot.com/2008/03/using-irepository-pattern-with-linq-to.html) T GetById(int id); is the repository method, I am interested in. Inside the codebase, it converts the int id passed to lambda expression(p => p.Id == Id)...

linq collation conflict issue

Hello every one, I'm using linq to SQL and when I run this query var lstData = from s in dataTrackDB.datas join m in dataTrackDB.mkts on s.mktcode equals m.mktcode join n in dataTrackDB.mktnews on m.mktcode equals n.oldmktcode select new data ...

Property name repeated but with different data type

I have an table called Invoices with a column named Vendor. The Vendor column is a FK reference to a Vendors table with the PK being Id. My dbml creates the appropriate objects...Invoice and Vendor. However, my Invoice object has both a Vendor property (as a String) and a Vendor1 property (as a Vendor object). I thought it would have t...

Handing complex validation scenarios in ASP.NET MVC

I'm been working on a GetRuleViolations() method for my User class, but I'm getting a little hung up on on something: What happens when different actions require different business rules? My User table has the following columns: Id, UserRoleId, Username, and Password. Several actions involving User are possible (create new user, edit u...

Error: Sequence contains more than one element

I am getting the following error on production server.It works well on localhost. Error: Sequence contains more than one element ...

Correct interface use with Entity Framework / Linq-to-SQL

I'm about to show my inexperience here, but hey - like any developer I want to learn. Given the following interface: public interface IRepository { entityDB Database { get; set; } IQueryable<T> All<T>() where T:class, new(); T Single<T>(Expression<Func<T, bool>> expression) where T : class, new(); IList<T> Find<T>(Expr...

Inserting data based on ParentID, strange behavior ASP.NET MVC ?

Hi, I have a simple form which inserts a new Category with the given parentID (ServiceID). and my parent child relationship is this; Service > Category my url for creating a Category based on the ServiceId is this /Admin/Categories/Create/3 => "3 is the serviceID" and my Action method is this [AcceptVerbs(HttpVerbs.Post)] pub...

Will adding partial class properties ruin deferred execution?

If I add properties onto a linq entity (employees for example), that simply refer to other properties to implement an interface, return an IQueryable, and the where clause mentions those added properties that just point to other linq entity properties, will it cause the entire table to be loaded and filtered in memory instead of at the s...

LINQ - Minimize Records Returned - Correct Way to Write These Expressions

Employee is a sample entity type. var r1 = (from c in _ctx select c).Skip(5).Take(5); // my intent is to pull the first record from the query var r2 = (from c in _ctx select c).FirstOrDefault<Employee>(); // my intent is to pull the last record from the query. // any good way to ask for the result back in the reverse // orde...

Nested stored procedures containing TRY CATCH ROLLBACK pattern?

I'm interested in the side effects and potential problems of the following pattern: CREATE PROCEDURE [Name] AS BEGIN BEGIN TRANSACTION BEGIN TRY [...Perform work, call nested procedures...] END TRY BEGIN CATCH ROLLBACK TRANSACTION RAISERROR [rethrow caught error using @ErrorNumber, @ErrorMessage, ...

Adding a child entity to parent entityset

Wondering if there is a good way(generic method which is) that can dynamically add child entity to appropriate entity set of a parent. Right now I have to do something like this, and it's not very elegant: public int AppendChild<T>(PATIENT patient, T child) where T : EntityBase switch (typeof(T).Name) { cas...

Linq to SQL collections do not populate.

I have a Linq to SQL class. There is a one to many relationship in my database. The relationship maps correctly in the designer, and an EntitySet<> property is created in the designer. When I run the code, the EntitySet<> does not populate with any data, even though there are associated records, they do not populate into the EntitySet...

How to bind wpf ComboBox to Linq to SQL Foreign Key Property

I have a Linq to SQL EntitySet with a Foreign Key Relationship between two tables. The tables in question are a Task table (called Issues) and a Departments Table. The foreign key is the department name (Which is guaranteed unique). I am running into an issue in that you cannot change a Linq to SQL FK field if the corresponding data is l...

Is there a simple Linq to SQL generator with bi-directional serialization attributes?

I'm trying to find a way to generate Linq to SQL classes with bi-directional serialization attributes. Basically I want a DataMember tag (with an appropriate order) on every association property, not just the ones where the class is the primary key (like the Visual Studio generator and SQL Metal do). I checked MyGeneration, but didn't re...

How can I get a randomized collection out of linq-to-sql model?

What's the right syntax for this? var words= from h in db.Words orderby(a => Guid.NewGuid()).ToList()) //error select h; var words= from h in db.Words orderby((a => Guid.NewGuid()).ToList()) //error select h; var words= from h in db.Words orderby...

How do I refactor a common LINQ subquery into a method?

I'm struggling to come up with the right words to summarize this problem, so any input on what I can add to clarify it would be appreciated. The basic scenario is this: I have a basic CMS (with pages, users, etc.). Page is a LINQ data object, which maps directly to a Page table. I've added a method to the Page class called GetUserPerm...

Insert/Select with Linq-To-SQL

Is there a way to do an insert/select with Linq that translates to this sql: INSERT INTO TableA (...) SELECT ... FROM TableB WHERE ... ...

TextBox value not updated

I am fetching data from database to textbox using Linq.When i try update the same textbox value,it does not work. DAL.TournamentsDataContext tdc = new SchoolSports.DAL.TournamentsDataContext(); var tournamentTable = tdc.GetTable<DAL.Tournament>(); var tournamentRecord = (from rec in tournamentTable ...

Deserialize xml into a Linq to SQL object

I need to read in XML data posted from external systems, which will be formatted roughly as follows: <Applicant> <FirstName>John</FirstName> <LastName>Smith</LastName> <Address>12 Main St</Address> </Applicant> This is a direct mapping of my Linq to SQL Applicant class, excluding a few properties. What's the best way to deseria...