linq-to-sql

Is there any need for LINQ to SQL Entity classes to implement INotifyPropertyChanging in an ASP.NET MVC Project?

I am using the code generated using SQLMetal for my database entities. They all implement INotifyPropertyChanging and INotifyPropertyChanged, and because of those dependencies, their is a ton of extra code in the property setters. I couldn't think of an instances for a regular ol' web page where one object would need to be notified of an...

Derived tables in Linq to SQL

I would like to implement this in Linq to SQL: select * from ( select * from Orders) as A Obviously this is a pointless example, but I just can't figure out how to do it! ...

Pipes and Filters and CompiledQuery.Compile

Hi guys I have started using linq to sql and the entity framework and have found the development experience to be fairly good. Like the way you can break a query apart and combine different queries is quite nice - see pipes and filters. But the problem that I have found is that performance can be greatly increased (in my case by a fa...

LinqToSql - Prevent sub queries when limiting number of rows returned

Dim query = (From p in Parent _ select _ p.ID, _ Tags = String.Join("|", p.Child.Select(Function(c) c.Tag.TagName).ToArray)).Take(100) In the above query, when using Take to limit the rows returned, a separate SQL query is executed for each row to return the 'Tags' field. If I remove Take(100), a single query to sen...

What's the advantage of mapping a binary column to System.Data.Linq.Binary instead of byte[]?

LINQ to SQL by default maps a binary column (varbinary, image, ...) to a property of the type 'System.Data.Linq.Binary'. Working with binary data this way is not that hard, but you can manually change that mapping to 'byte[]', making it easier to work with binary data (since you don't have to convert it in code anymore. What's the disad...

ASP.NET MVC posted entity not mapping to LINQ model

I have a page which is strongly typed to my "User" class. When it is loaded, I load it by Id from the database and pass it to the view. When the edit form is posted, the object gets posted to the controller method fine, with some other parameters. The object has its properties filled from the form, but it's ID (which obviously isnt on t...

OnFieldChanging Validation with Linq-to-SQL and MVC

I have the following partial methods in my partial class that is attached to an object in my Liq to SQL model. The first validation check in each method works fine for checking a valid entry in each. However the second if statement is used to check that the user has set at least one of the fields, but the methods are never actually call...

Will_paginate for ASP.NET MVC

I was run across issue to paging my list object in asp.net mvc where my object is simply load by LINQ-to-SQL. Is it some kinds of will_paginates command? in rails, i can do like Users.paginate(:all, :page => 1, :page_size => 20) ...

Clone Linq object Error "Object graph for type 'TestLinq.PersonAddress' contains cycles and cannot be serialized if reference tracking is disabled."

Hi to all I Need to clone row using linq. i found this method: public static T Clone<T>(this T source) { var dcs = new System.Runtime.Serialization .DataContractSerializer(typeof(T)); using (var ms = new System.IO.MemoryStream()) { dcs.WriteObject(ms, source); ...

LInq to SQl problem....Please help

I have the following data ProductId Description cost 12 test 0.0 12 test 8.8 12 test 7.9 27 asdf 9.0 27 asdf 2.0 27 asdf 2.0 I want the following result 12 test 0.0 / test8.8/test 7.9 27 asdf 9.0/asdf 2.0/ asdf 2.0 so far i could only come up w...

dynamic linq contains

Hello all, i search for a dynamic linq-to-sql Contains (StartsWith / EndsWith) method. I’ve tried the following code, but it didn't work. Any ideas? public static IQueryable<T> WhereContains<T, V>(this IQueryable<T> queryable, string propertyName, V propertyValue) { ParameterExpression pe = Expression.Parameter(typeof(T), "p"); ...

Help installing Dynamic Linq extension

Im trying to follow this tutorial and Haack seems to use Dynamic Linq but nowhere can I find how to install it... I know Im supposed to add a reference but Im really clueless in that area.. Im new to this, please help. ...

Linq-to-SQL forces me to Rebuild to see changes. Why?

In one of my current projects we keep running into this very wierd problem with Linq-to-Sql: If we update some properties of some objects (that are mapped to the db) and then SubmitChanges as usual, we are not able to see these changes until we rebuild the entire solution in visual studio. How come? ...

When does the DataContext will open a connection to the DB?

I am using L2S to access my MSSQL 2008 Express server. I would like to know when the DataContext will open a connection to the DB? and will it close the connection right after it opened it? For example: var dc = new TestDB(); // connection opened and closed? dc.SomeTable.InsertOnSubmit(obj); // connection opened and closed? foreach...

How to use transactions in DotNetNuke (entangled with L2S)?

I use L2S at my module. The problem occurs while I'm using the default DNN entities at the same TransactionScope with my L2S data access, then I get a DTC request which I want to avoid. How can I share the connection/transaction for both DNN entities and my L2S data access? ...

LINQ to SQL complex query problem

Hi all, I have 3 tables: Principal (Principal_ID, Scale), Frequency (Frequency_ID, Value) and Visit (Visit_ID, Principal_ID, Frequency_ID). I need a query which returns all principals (in the Principal table), and for each record, query the capacity required for that principal, calculated as below: Capacity = (Principal.Scale == 0 ? 0 ...

Modular Application Design and LINQ, Is it possible?

We are designing a large system and are using PLINQO for our data access. The problem doesn't lay in PLINQO but rather LINQ, I think. We want to make a modular design, ie possibly having multiple and different datacontexts. LINQ doesn't like this. Has anyone thought of a solution, issues or alternatives? Most things I see out there ...

Linq to sql - After call InsertOnSubmit(newItem) in code, Inserted Item does not show in DataGridView

Hi to all! I want to insert row into table using linq. I wrote this code var db = ((Table<PersonAddress>)personAddressBindingSource.DataSource); db.InsertOnSubmit(new PersonAddress { Address = "abc", PersonId = 5 }); DataGridView connected to personAddressBindingSource. but when run above code, dataGridView not show new row before ca...

How to generate private Linq to SQL classes?

I'm trying to figure out how to make the generated Linq to SQL classes be marked private instead of public, so that it is not visible outside the assembly. There doesn't seem to be a way to do this in the Visual Studio O/R designer or the SqlMetal tool, unless I'm missing something. Has anyone found a way to do this? I'm asking becaus...

LINQ: Get list of letters which have matching records

Ok, this is an interesting problem I think I have a list of items in a db, which have authors. (1 to 1 relationship, "authorId" is the foreign key). I need to get a list of letters in the alphabet which have a user to match it (by Surname) For instance, lets pretend there are only 3 items in the db. They were contributed by Mr Car, Mr...