Update Detached Entities

September 29, 2008 at 3:00 pm (.NET, LINQ, SQL)

Probably one of the most asked questions with LINQ to SQL, is how do you update detached entities. Often people will simply resort to doing a SELECT to get the entity into the datacontext and then update the data.

Steve Michelotti describes how to do it here:

http://geekswithblogs.net/michelotti/archive/2007/12/17/117791.aspx

and if your entity has child objects check this post out:

http://geekswithblogs.net/michelotti/archive/2007/12/30/118076.aspx

Advertisements

Permalink Leave a Comment

Improve LINQ to SQL performance

May 5, 2008 at 12:21 pm (LINQ, SQL)

While it is easy to get carried away with using LINQ to SQL, developers have the responsibility to understand what is going on under the hood and to ensure that things are running as smoothly and efficiently as possible.

The following blog post describes 10 tips from improving LINQ to SQL performance, highly recommended for anyone using LINQ to SQL.

Permalink 1 Comment

January 2008 release of SQL Server 2005 Best Practices Analyzer

January 21, 2008 at 11:38 pm (Free, Microsoft, SQL, Utilities)

Microsoft has released a new version of the SQL Server 2005 Best Practices Analyzer tool. The tool is from a Database Administrator’s (DBA) perspective and not from an architect nor developer’s perspective.

Check it out here:

http://www.microsoft.com/downloads/details.aspx?FamilyId=da0531e4-e94c-4991-82fa-f0e3fbd05e63&displaylang=en

Permalink Leave a Comment

Entity Framework FAQ

January 16, 2008 at 2:32 am (LINQ, Microsoft, SQL)

With LINQ become more predominate every day, eventually some important will be asked as developers need to adopt new and different ways of accessing data repositories.

I recently came across a great (and detailed) FAQ that is sure to answer most questions.

http://blogs.msdn.com/dsimmons/pages/entity-framework-faq.aspx

I certainly answered my question, but not with the answer I was hoping for :(. Automatic mapping between Enums and a column in a table is not supported.

http://blogs.msdn.com/dsimmons/pages/entity-framework-faq.aspx#_Does_the_EDM/EF

I hope they rethink this as that kind of simplicity is what increases adoption of new technologies. It’s  one the things that convinced me to start using NHibernate. Even LINQ to SQL supports automatic enum mapping.

Permalink Leave a Comment

Free Database Compare

January 10, 2008 at 6:08 pm (Free, SQL, Utilities)

I recently came across an interesting looking program by StarInix called Free Database Compare 2.0. The great thing is that is support Microsoft SQL Server and MySQL.

Permalink Leave a Comment

Getting Windows to Search within .SQL files

August 20, 2007 at 12:02 pm (SQL, Windows)

With Windows XP the default behaviour for searching within files will ignore .SQL files.

To get around this you can add a registry setting which will force Windows to treat .SQL files as text so it can search within the file.

  1. Open regedit
  2. Go to HKEY_CLASSES_ROOT\.sql
  3. Add a new key PersistentHandler
  4. Set the default value for the key to {5e941d80-bf96-11cd-b579-08002b30bfeb}

That’s it. You can do this for any other file type as well.

Perry

Permalink 7 Comments

SQL Snippet for Paging

April 18, 2007 at 11:49 am (SQL)

Microsoft SQL 2005 finally introduced better support for doing paging at the database level. I’m a little disappointed that MS is not pushing to use this as the default method for paging, instead of relying on ASP.NET controls.

1 USE AdventureWorks 2 GO 3 4 SELECT * FROM ( 5 SELECT 6 ROW_NUMBER() OVER (ORDER BY SellStartDate ASC) AS rownumber,* 7 FROM Production.Product 8 ) AS Product 9 WHERE rownumber between @FromRow AND @ToRow

Permalink Leave a Comment