linq-to-sql

Inserting and Updating using Linq-2-SQL

L2SQL seems great as long as I stick to read-only operations. As soon as I need to start changing fields, things get a bit hairy. In particular, I'm running in to two distinct problems. First, I'm attempting to populate a table with an arbitrary number of rows. The schema is mostly irrelevant, but it does have a 'BIGINT' primary key ...

Auto-genereate DBML from entities?

Is there a way to generate the DBML file from entity classes instead from database tables? This would be very useful for prototyping, where one just creates a logical model and let's the auto-generated tool to create the DBML file. With DBML file, one can use SqlMetal to generate Linq to SQL classes and be done with it. So, to prototype ...

How do I map view columns in Linq to Sql to related objects similar to foreign key behavior?

I have a view that returns ID columns that I want linq to sql to expand automatically. Is this possible? (It needs to translate to sql) I tried decorating my partial class with an Association attribute but this seems to fail internal mapping validation. Then I tried creating associations in the designer but that didn't seem to generate ...

Model validation and LINQ to SQL

I want to validate my linq2sql object differently based on its state (new object and updating an existing object.) An example is a User object that hash a Password byte[] field. This stores the hash of the password in the database. However, the user must type in PasswordText and PasswordText2 only if its a new user. I added two extra ...

Does Entity Framework/LINQ to SQL Data Binding use reflection?

Forgive me if this has been asked before; I did a search but couldn't find anything that specifically answered this question, but I'd be happy to be referred. I'm taking a peek at both the Entity Framework and LINQ to SQL, and while I like the systems (and of course the LINQ integration) I'm a little skeptical on the data-binding aspect...

How can a Ruby on Rails style counter cache be implemented using Linq2Sql?

How can for example a Blog post comment counter cache be implemented using linq2sql? The way I currently implement this in a site I am developing is using hand coded sql queries and the ExecuteCommand() adhoc sql execution method of the linq2sql datacontext. I would like to know if there is a better/simpler approach using linq2sql tha...

XDocument.Save() without header

I am editing csproj files with Linq-to-XML and need to save the XML without the <?XML?> header. As XDocument.Save() is missing the necessary option, what's the best way to do this? ...

How can I query the range of date which one product has not been ordered? (LINQ)

I have three tables, Products(ProductID, ProductName) Orders(OrderID, OrderDate) OrderDetails(ProductID, OrderID) Junction table between Products and Orders. For example, there are Three ProductID in Products table A01, A02, A03 Four OrderID in Orders table 1. 01/01/2009, 2. 03/01/2009, 3. 05/01/2009, 4. 07/01/2009. OrderDetails d...

Problem with paging with Linq and DataTable

Hi, I'm writing a small web app in VB.NET and I would like to do paging for my DataTable in the following function : Public Shared Function Testing(ByVal KeyWord As String, ByVal CurrentPage As Integer, ByVal PageSize As Integer) As DataTable Dim db As New BibleDataClassesDataContext Dim dtDataTableOne = New DataTable...

refactoring LINQ IQueryable expression to remove duplicated portions of queries

I have some linq queries that have redundancy I'd like to factor out a single piece of code. These are join experssions that are IQueryable, and its important I don't cause the query to be evaluated earlier than it would be without the refactoring. Here is a simplified query: var result = from T in db.Transactions join O in db.Orders...

How does linq determine value changes?

If the value of a field is not actually changed but reassigned the same value, will that reassignment be marked for update when submitting to database? ...

Mapping Linq Entities and Domain Objects and object tracking

If I map my Domain objects to linq Entities will I now not be able to track changes when saving my domain objects? So for any change in my model that i wish to make, once I map the object to linq entities for submission to db, all object values will be submitted to the db by linq since it it goes through a mapping first? Or would the obj...

Linq To SQL Many to Many

I would like to know how to save new associations for entities with many to many relationships. I've got 3 tables: Partner - -- ParnterID -- ParnterName -- Etc PartnerRegion -- PartnerRegionID -- RegionID -- PartnerID Region -- RegionID -- RegionName -- Etc I have the entities created, and the associations appear in my ent...

Return Multiple Results in Linq2Sql without a stored procedure?

Hi folks, i would like to return two record sets from a simple database table with one Linq2Sql query. I know how to do it if this was using Linq2Sql calling a stored procedure, but I don't want to use a stored procedure. Is it possible to do it? I've found an article here that has a suggested solution, but i hate the idea of having ...

Selecting a single item with linq2sql query

Hey everyone, I'm trying to retrieve a single entity from a Linq2Sql query, but I'm having trouble finding the 'pretty' way of doing it. Here's what I've found that works: var states = from state in dc.States where state.Id == j.StateId select state; State s = states.ToList<State>().ToList()[0]; I'm hoping this isn't the best way o...

Linq criteria query

Linq query for: Record in MyTable has two child records, I want to check if either of these records have an Id from a list of integers. ...

Can LINQ-to-SQL fill non-ColumnAttribute-marked properties when using DataContext.ExecuteQuery?

Given this table: CREATE TABLE [Comments] ( [Id] [int] IDENTITY(1, 1) NOT NULL, [Text] [nvarchar](600) NOT NULL ) With this model class: [Table(Name="Comments")] public class Comment { [Column(AutoSync = AutoSync.OnInsert, DbType = "Int NOT NULL IDENTITY", IsPrimaryKey = true, IsDbGenerated = true)] public int Id { get; ...

The || (or) Operator in Linq with C#

Hi, I'm using linq to filter a selection of MessageItems. The method I've written accepts a bunch of parameters that might be null. If they are null, the critea for the file should be ignored. If it is not null, use it to filter the results. It's my understanding that when doing an || operation is C#, if the first expression is true, t...

Need help with Sql Server Full Text Search problem.

Hi folks, I have a Full Text Catalog on single table, with three fields defined :- TABLE: Animals Fields: Name, Breed, LatinName. Now, the Catalog seems to be working perfectly. eg. CREATE FUNCTION AnimalSearch ( @Name NVARCHAR(200) ) RETURNS TABLE AS RETURN ( SELECT KEY_TBL.[Key] as Name, KEY_TBL.RANK as Relevan...

Using LINQ to SQL to read stored procedures.

Does anyone know a way to access the text of stored procedures using LINQ to SQL? I'd like to audit a set of stored procedures to check that they contain all contain some common code. It feels like there should be a nice way of opening them through a LINQ to SQL data context but I don't know how. Any suggestions? ...