in

Dé specialist in .NET trainingen en consultancy

Jo-wen Mei

augustus 2009 - Posts

  • EF: use GetObjectByKey() for better performance

    When I want to fetch an entity, I normally have a method that uses a query.

    image

    This method will always query the database and you will have an up-to-date entity.

     

    But if you need better performance perhaps GetObjectByKey() is a better option.

    This method will check the cache first and returns the entity when it has been loaded already.

    When it’s not in the cache, it would still query the database.

     

    You need to supply an EntityKey(string qualifiedEntitySetName, string keyName, object keyValue)

    I’ve made a generic method which automatically determines the entitySetName:

    image

    here’s an example of a call:

    image

     

    ps: I have hardcoded the keyName, because all my tables have an “ID” primary key.

    When this is not the case, check out the CreateEntityKey method

  • Generate INSERT INTO script for existing data in Sql Server 2008

    It always amazes me how little features are built into Sql Server Management Studio.

    One of these (trivial) things is to generate a script which inserts existing data.

    Fortunately, it has become a feature in Sql Server 2008.

    short story: right click the database > tasks > generate scripts > enable “script data” option

    full story: here

    Posted aug 15 2009, 06:31 by Jo-wen with no comments
    Filed under:
  • VPN shortcut in Windows 7

    I’m amazed how hard it is to create a shortcut to a vpn connection.

    In Vista it already wasn’t that obvious, and in windows 7 it’s even more hidden!

    Hopefully I can save you a couple of minutes while performing this incredibly complex task:

    check out “Network and Sharing Center” and select “Change adapter settings” !!! (duh)

    From here you can create a vpn shortcut on your desktop.

    Posted aug 12 2009, 05:00 by Jo-wen with no comments
    Filed under:
  • Sql Server 2008: Can't save changes that require Recreation of Database

    There's a silly new default in SQL Server's Management Tools: When you design a table in a database and then try to make a change to a table structure that requires the table to be recreated, the management tools will not allow you to save the changes.

    The fix is: Go to

    Tools | Options | Designers | Tables and Designers and uncheck the Prevent Saving Changes that require table re-creation option

    More details

    Posted aug 10 2009, 03:22 by Jo-wen with no comments
    Filed under: