linq-to-sql

LINQ-To-SQL and Many-To-Many Relationship Deletions

I have a many-to-many relationship between two tables, let's say Friends and Foods. If a friend likes a food I stick a row into the FriendsFoods table, like this: ID Friend Food 1 'Tom' 'Pizza' FriendsFoods has a Primary Key 'ID', and two non-null foreign keys 'Friend' and 'Food' to the 'Friends' and 'Foods' tables, respectively. Now...

What can map database tables like LINQ to SQL did?

A good thing in LINQ to SQL was a fast and reliable way to map database tables and convert them into classes accessible from c# project. However it is no longer recommended to create projects using LINQ to SQL. What is its substitute? What kind of tool should I use in VS 2010 today if I want to have the same functionality as I had with ...

Which column type should I use for storing HTML of an unknown size?

What column type should I use for storing html content from a website with an unknown size? (I'm scanning certain html pages, and create an database entry if there are changes between the last stored entry and the current html code.) My database is a MSSQL 2008 express database. ...

Groupby in relationtable

I am creating some tag functionality for a forum using linq2sql, and I have two tables [Tag] TagId TagName [ForumTagRelation] TagId ForumId I would like to retrieve, like SO, the most popular tags. I have tried to do this by: List<Tag> popularTags = db.Tags.Select(x => x.ForumTagRelations.GroupBy(y => y.TagId).OrderByDescen...

LINQ to SQL - Nullable<int> ForeignKey = An attempt was made to remove a relationship between...?!

Hi. I have a data model like this: [Table(Name = "DayWorks")] public class DayWork { [Column(DbType = "Int NOT NULL IDENTITY", IsPrimaryKey = true, IsDbGenerated = true)] public int ID { get; set; } ... /* no any EntitySet here for extensionable model purposes (really need) */ } [Table(Name = "Documents")] public class Document { ...

How to use Linq To Sql to get Users who has less than 2 photos?

The scenario is I want to get the users who has less than 2 photos. There are two table: [Users] (UserId, UserName) [UserPhotos] (PhotoId, PhotoName, UserId) UserId is a Foreign Key but I do not want to use association like user.Photos. A user may have none photo in the [UserPhotos] table. How to use Linq To Sql to get List<User...

LINQ to SQl updating primary key field?

I have a linq to sql table/class that uses a GUID as both a primary key and as foreign key. This problem came up when factoring some code that previously worked. The exception generated is "Operation is not valid due to the current state of the object." The process I use is as such: aspnet_User user() = new aspnet_User(); aspnet_use...

Linq to Sql, Repositories, and Asp.Net MVC ViewData: How to remove redundancy?

Linq to SQL creates objects which are IQueryable and full of relations. Html Helpers require specific interface objects like IEnumerable<SelectListItem>. What I think could happen: Reuse the objects from Linq to SQL without all the baggage, i.e., return Pocos from the Linq to SQL objects without additional Domain Model classes? Extrac...

Linq-To-Sql with WCF, Models, and POCO ViewModels Disconnected "DataContext" Timestamp/Rowversion

I have a Linq-To-Sql based repository class which I have been successfully using. I am adding some functionality to the solution, which will provide WCF based access to the database. I have not exposed the generated Linq classes as DataContracts, I've instead created my own "ViewModel" as a POCO for each entity I am going to be returnin...

ASP.NET MVC 2 RC2 Model Binding with NVARCHAR NOT NULL column

PLEASE NOTE: I've answered my own question with a link to an answer to a similar question. I'll accept that answer once I'm allowed to (unless anyone comes up with a better answer meantime). I have a database column defined as NVARCHAR(1000) NOT NULL DEFAULT(N'') - in other words, a non-nullable text column with a default value of blank...

Update specific rows in LINQ to SQL result set.

I have a page with a form on it and needs a range of dates. Thus I've placed a number of textboxes on the page into which users can type dates. When the user clicks the save button I want to trigger a LINQ update to the SQL Server...all the rows already exist, so I'm just updating existing data. How can I do this? For example, lets say m...

Extending LINQ classes to my own partial classes in different namespaces?

I have a .dbml file which of course contains the auto-generated classes based on my tables. I would however, like to extend them to my own classes. Typically I design such that each of my tables get their own namespace in their own folder containing all of their associated dao and service classes. So if I am dealing with a page that onl...

Sorting Anonymous Types

I have a question of how to sort an anonymous type. Using Linq2SQL I have the following query, which returns a list of submissions: var submissions = EventSubmissions .Where(s => s.EventId.Equals(eventId)); Consider the following interface (somewhat simplyfied): public interface IQuerySorter { IOrderedQueryable Sort(IQueryab...

IEnumerable<string> => unique string[]

Hello, I have a collection of IEnumerable<sentence> (sentence = string) I want to split all sentences to words (ex: .Select(t => t.Split(' ')), and after this I need to group this query by words to get a list of unique words. Please, Help ...

[C#]How to introduce retry logic into LINQ to SQL to deal with timeouts?

I need to find ways to add retry mechanism to my DB calls in case of timeouts, LINQ to SQL is used to call some sprocs in my code... using (MyDataContext dc = new MyDataContext()) { int result = -1; //denote failure int count = 0; while ((result < 0) && (count < MAX_RETRIES)) { result = dc.myStoredProc1(...); ...

How do I get Linq-to-SQL to refresh its local copy of a database record?

Suppose I have an Orders table in my database and a corresponding model class generated by the VS2008 "Linq to SQL Classes" designer. Suppose I also have a stored procedure (ProcessOrder) in my database that I use to do some processing on an order record. If I do the following: var order = dataContext.Orders.Where(o => o.id == orderId)...

"Row not found or changed" Problem

Hi there, I'm working on a SQL CE Database and get into the "Row nor found or changed" exception. The exception only occurs when I try to update. On the first Run after the insert it shows up a MemberChangeConflict which says, that my Column Created_at has in all three values (current, original, database) the same. But in a second attemp...

Gridview buttonfield works LinkButton doesn't

I've been fighting this problem for many hours now and could really use some help :-) This is the grid <asp:GridView ID="annonceView" runat="server" AutoGenerateColumns="False" DataKeyNames="Id" DataSourceID="dataSourceAnnoncer"> <Columns> <asp:BoundField DataField="Productname" HeaderText="Productname" /> ...

What T-SQL is being executed by my LINQ-to-SQL queries?

Is there any easy way to find out what T-SQL is being generated by my LINQ-to-SQL query? Preferably using some LINQ entrypoint, rather than a licenced software product like Microsoft SQL Server Profiler or LINQ-to-SQL Profiler. ...

building an ASP NET MVC site, should i go with linq to sql?

So I'm about to start a new website from scratch and I've spent about a week trying to figure out what technology to go with. I'm sold on ASP NET MVC. I'm 100% sure I'm going to love using that. but what i am not so sure about yet is using Ling-to-SQL. So far I've gathered some data... StackOverflow uses it - can't be that bad can be ...