September, 2010

  • Wriju's BLOG

    LINQ : From Basics to Query

    • 0 Comments

    Many of us are aware of LINQ today. LINQ is an amazing programming language feature. During my discussions I find a lot of myths around understanding. Here I have tried to demonstrate from some basics of C# 3.0 language enhancements to delegate, anonymous type, lambda expression and finally LINQ. How it has evolved.

    image

    http://channel9.msdn.com/posts/LINQ-Evaluation-From-Basics-to-Implementation

    Namoskar!!!

  • Wriju's BLOG

    Entity Framework finding the differences between production database and model’s schema

    • 2 Comments

    We develop our ADO.NET EF model from the development environment db and then when finally run it to the production we might find that DBA might have added few rules or renamed the database columns. Then our application would start throwing errors. One easy way to get it rectified is to run query against each entity and catch if any error. Otherwise EF gives some public API to use.

    Background

    I have created my edmx from my dev database and it has just two columns.

    image

    Now at production let’s suppose my column is EmpNameTest. How can I programmatically check the difference?

    I was going through the tool EdmGen.exe and it gives us an option to validate via

    EdmmGen /mode:ValidateArtifacts /inssdl:Model1.ssdl /inmsl:Model1.msl /incsdl:Model1.csdl

    All the three files can comes from your edmx file. If you choose the option from edmx file to be part of your output directory, then it will same all of then individually to your output directory.

    image

    Now, I will generate the ssdl at runtime by reading the production database, this gets saved to my output directory.

    Create SSDL
    1. private static void CreateSSDL(string connStr, string provider, string modelName, string newSSDLFileName)
    2. {
    3.     IList<EdmSchemaError> ssdlErrors = null;
    4.  
    5.     // generate the SSDL
    6.     string ssdlNamespace = modelName + "Model.Store";
    7.     EntityStoreSchemaGenerator essg = new EntityStoreSchemaGenerator (provider, connStr, ssdlNamespace);
    8.     ssdlErrors = essg.GenerateStoreMetadata();
    9.  
    10.     // write out errors
    11.     if ((ssdlErrors != null && ssdlErrors.Count > 0))
    12.     {
    13.         System.Console.WriteLine("Errors occurred during generation:");
    14.         //WriteErrors(ssdlErrors);
    15.         return;
    16.     }
    17.  
    18.     essg.WriteStoreSchema(newSSDLFileName);
    19. }
    p

    Now call it from your method,

    1. string newSSDLFileName = "MyTestModel.ssdl";
    2.  
    3. //Create NEW SSDL at runtime
    4. CreateSSDL(myConnectionString, "System.Data.SqlClient", "Sept2010", newSSDLFileName);

    Then run the validate method as below,

    Validate
    1. private static void Validate(string newSSDLFile)
    2. {
    3.     //Reading SSDL from generayted file
    4.     XElement s = XElement.Load(newSSDLFile);
    5.  
    6.     //Reading CSDL and MSL from assembly
    7.     XElement c = XElement.Load(Assembly.GetExecutingAssembly().GetManifestResourceStream("Model1.csdl"));    
    8.     XElement m = XElement.Load(Assembly.GetExecutingAssembly().GetManifestResourceStream("Model1.msl"));
    9.  
    10.     // load the csdl
    11.     XmlReader[] cReaders = { c.CreateReader() };
    12.     IList<EdmSchemaError> cErrors = null;
    13.     EdmItemCollection edmItemCollection =
    14.         MetadataItemCollectionFactory.CreateEdmItemCollection(cReaders, out cErrors);
    15.  
    16.     // load the ssdl
    17.     XmlReader[] sReaders = { s.CreateReader() };
    18.     IList<EdmSchemaError> sErrors = null;
    19.     StoreItemCollection storeItemCollection = MetadataItemCollectionFactory.CreateStoreItemCollection(sReaders, out sErrors);
    20.  
    21.     // load the msl
    22.     XmlReader[] mReaders = { m.CreateReader() };
    23.     IList<EdmSchemaError> mErrors = null;
    24.     StorageMappingItemCollection mappingItemCollection =
    25.         MetadataItemCollectionFactory.CreateStorageMappingItemCollection(
    26.         edmItemCollection, storeItemCollection, mReaders, out mErrors);
    27.  
    28.  
    29.     // validate the mappings
    30.     IList<EdmSchemaError> viewGenerationErrors = null;
    31.     viewGenerationErrors = EntityViewGenerator.Validate(mappingItemCollection);
    32.             
    33.     if (cErrors.Count > 0 || sErrors.Count > 0 || mErrors.Count > 0 || viewGenerationErrors.Count > 0)
    34.     {
    35.         Console.WriteLine("Error Error!!!");
    36.     }
    37.     else
    38.     {
    39.         Console.WriteLine("No Error :)");
    40.     }
    41. }

    I found this solution from the EdmGen2.exe. You will find the whole source code available at http://code.msdn.microsoft.com/EdmGen2

    Two points before you try it out,

    • Add the assembly System.Data.Entity.Design from Windows\Assembly folder
    • Change the Edmx’s Metadata Artifact Processing property to Embed in Output Assembly

    Namoskar!!!

     

  • Wriju's BLOG

    Channel 9 : Visual Studio 2010 Database Development

    • 0 Comments

    Recently I have posted one Channel 9 video on How to Develop Database using Visual Studio 2010. From keeping it within Source Control to Refactoring. It’s just a fun.

    http://channel9.msdn.com/Blogs/wriju/Visual-Studio-2010-Database-Development

    image

    Namoskar!!!

  • Wriju's BLOG

    Channel 9 : Team Foundation Server 2010 – Creating Team Project

    • 0 Comments

    I have recently added one video in Channel 9 at http://channel9.msdn.com/Blogs/wriju/Team-Foundation-Server-2010--Creating-Team-Project 

    image

    I love the new look of Channel 9.

    Namoskar!!!

  • Wriju's BLOG

    Internet Explorer 9 Beta Guide for Developers

    • 0 Comments

    More on Developer Details at http://msdn.microsoft.com/en-us/ie/ff468705.aspx

    Namoskar!!!

  • Wriju's BLOG

    Internet Explorer 9 : The First Experience

    • 0 Comments

    While Installing…..

    image

    After it installs the IE9 the machine will be restarted and you will get a super cool browser.

    image

    IE 9 Rocks!!!

    image

    Namoskar!!!

  • Wriju's BLOG

    Internet Explorer 9 / IE 9 Download From Here

    • 0 Comments

    Internet Explorer 9 or IE9 is simply magic and launched today (Sept 15, 2010). Download it from here at http://windows.microsoft.com/en-US/internet-explorer/download/ie-9/worldwide

    Lots of canned demos are at http://ie.microsoft.com/testdrive/. I personally liked the HTML 5 power http://ie.microsoft.com/testdrive/

    Namoskar!!!

  • Wriju's BLOG

    Generate Dummy Test Data using Data Generation Plan

    • 1 Comments

    Most of the time we struggle to get some dummy data for various types of testing. Data Generation Plan in Visual Studio 2010 helps to achieve it. It not only fills the tables based on the number of rows selected by us it also takes care of the relationship if any. One thing to remember is about the quality of data, all junk.

    Let’s suppose you have a database project of Northwind. Now you need to create some 5000 categories to do a Load Testing. Very easy to achieve,

    Database Project > Add New Item > Data Generation Plan. Then choose the number of Rows.

    image

    Once done you can choose to run by hitting F5 or use menu,

    image

    Your dummy data is ready, please do not try to ready it :).

    Namoskar!!!

  • Wriju's BLOG

    Visual Studio 2010 and MSDN Licensing White Paper

    • 0 Comments

    To answer the common questions related to MSDN is available here http://www.microsoft.com/downloads/details.aspx?FamilyID=2b1504e6-0bf1-46da-be0e-85cc792c6b9d&displaylang=en

    Namoskar!!!

  • Wriju's BLOG

    Comparing Two SQL Server Schema using Visual Studio 2010

    • 0 Comments

    When you have two SQL Sever Databases and need to find the differences, Visual Studio comes really handy.

    Under Visual Studio 2010’s menu Data > Schema Compare. Once you choose New Schema Comparison

    image 

    Then you choose your databases. After you choose it you can also set the Schema Compare Settings. Once you press OK. It gives you the report.

    Let’s suppose you have one additional column in your database, it shows something,

    image

    You can further drill-down to find the details,

    image

    Now this also gives you the Script differences with highlight.

    image

    Then you can choose Write Update from menu

    image

    This will update you right selection (Target).

    Namoskar!!!

Page 1 of 1 (10 items)