linq-to-sql

Enabling editing of primary key field in ASP.NET Dynamic Data / LINQ to SQL

If you have a table with a compound primary key that is composed of a foreign key and other table columns, how do you get ASP.NET Dynamic Data to allow the non-foreign primary key table columns to be editable? ...

Can I return the 'id' field after a LINQ insert?

When I enter an object into the DB with Linq-to-SQL can I get the id that I just inserted without making another db call? I am assuming this is pretty easy, I just don't know how. Thank you. ...

How fast is LINQ?

I need to manipulate 100,000 - 200,000 records. I am thinking of using LINQ (to SQL) to do this. I know from experience that filtering dataviews is very slow. So how quick is LINQ? Can you please tell me your experiences and if it is worth using, or would I be better off using SQL stored procedures (heavy going and less flexible)? Wit...

Linq to SQL Grouping Child Relationships

I'm trying to run a LINQ to SQL query that returns a result in a grid view in a search engine style listing. In the simplified example below, is it possible to populate the collection with a comma-separated list of any children that the parent has (NAMESOFCHILDREN) in a single query? var family = from p in db.Parents whe...

Can you do LINQ-like queries in a language like Python or Boo?

Take this simple C# LINQ query, and imagine that 'db.Numbers' is an SQL table with one column, Number: var result = from n in db.Numbers where n.Number < 5 select n.Number; This will run very efficiently in C#, because it generates an SQL query something like "select Number from Numbers where Number < 5". What it ...

LINQ + type tables best practices

Whats the best design pattern to use for LINQ and type tables that exist in SQL. I have tables in SQL that constrain values to type values, and I want to be able to use this in my C# code as strongly typed values. My current approach for a 'PackageStatus' type is as follows: SQL Table PackageStatusType (int) desc (varchar) C# ...

How do I avoid a memory leak with LINQ-To-SQL?

I have been having some issues with LINQ-To-SQL around memory usage. I'm using it in a Windows Service to do some processing, and I'm looping through a large amount of data that I'm pulling back from the context. Yes - I know I could do this with a stored procedure but there are reasons why that would be a less than ideal solution. An...

How to solve "An attempt to attach an auto-named database for file..." SQL error?

I've got a local .mdf SQL database file that I am using for an integration testing project. Everything works fine on the initial machine I created the project, database, etc. on, but when I try to run the project on another machine I get the following: System.Data.SqlClient.SqlException : A connection was successfully established with t...

LINQ: custom column names

UPDATE I'm basically binding the query to a WinForms DataGridView. I want the column headers to be appropriate and have spaces when needed. For example, I would want a column header to be First Name instead of FirstName. How do you create your own custom column names in LINQ? For example: Dim query = From u In db.Users _ ...

Can LINQ (to SQL) do bitwise queries?

I have a table of Users that includes a bitmask of roles that the user belongs to. I'd like to select users that belong to one or more of the roles in a bitmask value. For example: select * from [User] where UserRolesBitmask | 22 = 22 This selects all users that have the roles '2', '4' or '16' in their bitmask. Is this possible to e...

Planning to use PostgreSQL with ASP.NET: bad idea?

Hi everyone! I'm currently planning the infrastructure for my future web project. I want to go the way Joel went with having one DB per client and now thinking which DB engine will be good for me. The best would be of course SQL Server, but I can't afford a full-blown version at this moment and I don't think SQL Server Express will be a...

Autogeneration of a DataContext designer file when using SqlMetal and Visual Studio

I am using SqlMetal to general my DataContext.dbml class for my ASP.net application using LinqToSql. When I initially created the DataContext.dbml file, Visual Studio used this to create a related DataContext.designer.cs file. This designer file contains the DataContext class in C# that is used throughout the app (and is derived from the...

LinqToSql and WCF

Within an n-tier app that makes use of a WCF service to interact with the database, what is the best practice way of making use of LinqToSql classes throughout the app? I've seen it done a couple of different ways but they seemed like they burned a lot of hours creating extra interfaces, message classes, and the like which reduces the b...

¿Cómo programar las extensiones Partial que Linq to SQL autogenera?

Hice una clase desde la herramienta Linq to SQL Clasees con VS 2008 SP1 Framework 3.5 SP1, en este caso extendí el Partial partial void UpdateMiTabla(MiTabla instance){ //Logica de negocio // Reglas de validación etc. } Mi problema es que cuando le doy db.SubmitChanges() si va al metodo UpdatemiTabla y hace las validaciones, pe...

LINQ Syntext Sequence

The following SQL SELECT * FROM customers converted to this in LINQ var customers = from c in customers select c; Is their any good reasones why the from and select is swaped? The only logical reason I can think of is for intellisens? For the intellesens to get resolved, it needs to know what it is querying (scop...

Getting a Linq-toSQL query to show up on a GridView

I have a pretty complicated Linq query that I can't seem to get into a LinqDataSsource for use in a GridView: IEnumerable<ticket> tikPart = ( from p in db.comments where p.submitter == me.id && p.ticket.closed == DateTime.Parse("1/1/2001") && p.ticket.originating_group != me.sub_unit select p.ticket ...

How do you define a type in a Linq 2 SQL mapping?

I'm trying to do my linq 2 sql objects manually, so I have the following code: var mapping = XmlMappingSource.FromXml(xml); using (DataContext ctx = new DataContext(conn_string, mapping)) { list = ctx.GetTable<Achievement>().ToList(); } and the XML looks like this: <?xml version="1.0" encoding="utf-8" ?> <Database Name="FatFight...

Define a one-to-one relationship with LinqToSQL

I'm playing around with LinqToSQL using an existing multi-lingual database, but I'm running into issues mapping a fairly important one-to-one relationship, so I suspect I am using the feature incorrectly for my database design. Assume two tables, Category and CategoryDetail. Category contains the CategoryId (PK), ParentId and TemplateId...

Is it possible to use Soundex (or other SQL functions) in LinqToSql?

Guess the title says it all. I'm refactoring some code currently implemented in stored procedures to use LinqToSql (for use in training). Is it possible to use SQL functions in a linqToSql Query? ...

LinqtoSQL filter and order by syntax

My Techie Bretheren (and Sisteren, of course!), I have a LinqToSql data model that has the following entities: I need to retrieve all advisors for a specific office, ordered by their sequence within the office. I've got the first part working with a join: public static List<Advisor>GetOfficeEmployees(int OfficeID) { List<Advisor>...