• Telerik Open Access Orm : Include Equivalent - FetchStrategy

    by Venkata Koppaka | Jun 13, 2011

    ADO.NET Entity Framework 4.0 has an friendly method for loading related objects in a explicit way by using "Include"

    Below is an example from MVC Music Store.

    1 public ActionResult Browse(string genre) 
    2         { 
    3             // Retrieve Genre and its Associated Albums from database 
    4             var genreModel = storeDB.Genres.Include("Albums") 
    5                 .Single(g => g.Name == genre); 
    6  
    7             return View(genreModel); 
    8         } 

    In this method, Generes and Albums are related so EF provides an easy way to get both in a single call.

    But the main topic of this post is how to achieve this behavior if you are using Telerik OpenAccess ORM.

    See the code below -

    1         public ActionResult Browse(string genre) 
    2         { 
    3             // Retrieve Genre and its Associated Albums from database 
    4             FetchStrategy fetchStrategy = new FetchStrategy(); 
    5             fetchStrategy.LoadWith<Genre>(g => g.Albums); 
    6             storeDB.FetchStrategy = fetchStrategy; 
    7  
    8             Genre genreModel = storeDB.Genres.FirstOrDefault(g => g.Name == genre); 
    9  
    10             return View(genreModel); 
    11         } 

    You will need a "FetchStargegy" and Load Genre with Albums while getting the results.

    Hope this helps.

    Cheers

    Venkata


    Go comment!
  • Working with ambigious controller names in MVC3

    by Venkata Koppaka | Apr 30, 2011

    If you are working with ASP.NET MVC2 or above you might want to have same controller name across multiple areas. For example you might have an Home Controller on your root of your website and also a Home Controller on the Admin Area of your website. Looks like a a reasonable thing to have

     

    But if you run your application you will have an error saying "Multiple Types were found that match the controller..." or like the screenshot below

     

    To overcome this error you need register a route specific to the area with the namespace. Use the code snippet below-

    public static void RegisterRoutes(RouteCollection routes) 
            { 
                routes.IgnoreRoute("{resource}.axd/{*pathInfo}"); 
     
                //General Route 
                routes.MapRoute( 
                    "Default", // Route name 
                    "{controller}/{action}/{id}", // URL with parameters 
                    new { controller = "Home", action = "Index", id = UrlParameter.Optional }, // Parameter defaults 
                    new string[] { "AmbiguousControllers.Controllers" } 
                ); 
     
                //Route for Admin Area 
                routes.MapRoute( 
                    "Admin Default", // Route name 
                    "{controller}/{action}/{id}", // URL with parameters 
                    new { area = "Admin", controller = "Home", action = "Index", id = UrlParameter.Optional }, // Parameter defaults 
                    new string[] { "AmbiguousControllers.Areas.Admin.Controllers" } 
                ); 
     
            } 

    And now you can have multiple controllers with the same name.

     Hope this helps,

    Cheers

    Venkata

    Go comment!
  • Making your website IE9 friendly

    by Venkata Koppaka | Mar 21, 2011

    IE9 was released recently. It is brand new browser from Microsoft, which uses their new "Chakra" Javascript engine which makes it the fastest browser till date (even beating Chrome 10).

    IE9 has an interesting feature called "Site Pinning". This blog post talks about how to change your website to make use of that and give the users of your website a "app" feel on Windows 7.

    To begin with let us first add a shortcurt icon

    Add this line in the HEAD section of your page.

     

        <link rel="shortcut icon" type=image/x-icon href="/images/shortcut.png" /> 
     

    and when you drag the tab in IE on to your Windows 7 taskbar, your shortcut icon shows up in task bar and the the you get a nice color scheme which is similar to your website when you open your website.

     

    IE9 also lets you add "Jump list tasks", which can be done by the following snippet -

    <meta name="msapplication-task" content="name=Follow on Twitter;action-uri=http://twitter.com/subbaraokv;icon-uri=/images/twitter_ico.ico" /> 
        <meta name="msapplication-task" content="name=Subscribe to Feed;action-uri=http://www.bluegenegeek.com/blogs.rss.ashx;icon-uri=/images/feedicon.ico" /> 
        <meta name="msapplication-task" content="name=About Me;action-uri=http://www.bluegenegeek.com/About.aspx;icon-uri=/images/AboutMe.ico" /> 

    The basic idea behind the above above snippet is you can add "tasks" with your own text and urls and have a nice little icon to go along with it.

    Once this is done this is how it would look like -

     

    Hope this helps

    Cheers

    Venkata

    Go comment!
  • Getting Started with Mercurial and TortoiseHG

    by Venkata Koppaka | Feb 05, 2011

    Mercurial is a distributed version controls system (DVCS) and TortoiseHG is a GUI based Mercurial Client for Windows.

    To install TortoiseHG on windows, download the TortoiseHG client from here.

    Run through the installer.

    Once the installation is finished -

    Open the folder that you want to create a repository for

    Right click on the folder go to TortoiseHG Menu and click on Global Settings

     

    On the Global Settings window go to Commit and enter your Name you might want to follow a format like <Name> <Email>.

    Click OK.

    Now to create a repository, right click on the source code folder go to TortoiseHG menu and click on Create Repository here.

    Hit Create on the init screen.

    With this you have created a new repository using Mercurial and TortoiseHG. You can now commit code to the repository.

    Now if you want to synchronize your local repository to cloud code hosting service like BitBucket you will have to setup sync settings. 

    To get to the sync settings page right click on the folder you want to sync click TortoiseHG -> Repository Settings.

     

    On the repository settings page, click Synchronize and click add button for remote repository settings grid.

    Type in the URL, of the repository and username and password if any to connect to that repository and click ok. You will now see the remote repository in the list.

    Click OK and save the settings.

    Now to commit to your cloud code hosting service, click TortoiseHG->Synchronize

    In the synchronize window choose your remote path we added earlier and click Push.

     

    And your code will be pushed to your clould code hosting service.

    Hope this helped

    Cheers

    Venkata

    Go comment!
  • Adding Telerik Extensions for MVC3 using NuGet awesomeness

    by Venkata Koppaka | Feb 04, 2011

    This is fourth in the series posts I am doing to cover Telerik Extensions for ASP.NET MVC3(Updating the MVC3 from today's post).

    1. Getting Started with Telerik Extensions for ASP.NET MVC 
    2. Telerik Extensions for ASP.NET MVC - The Grid
    3. Telerik Extensions for ASP.NET MVC - The Editor 

    In today's post I will talk about using Telerik Controls via Nuget.

    Let us create a new MVC3 application and as with any MVC3 project you get the new ASP.NET View Engine called Razor.

    So let us create a new MVC3 project with Razor view engine.

    We are going to add Telerik Extensions to our MVC3 project via Nuget.

    Open up the Package Manager Console(View->Other Windows->Package Manager Console) and type this line in your PowerShell window

    PM> Install-Package TelerikMvcExtensions.MVC3 

     

    TelerikMVCExtension.MVC3 is the name of the package you want to install.

    Alternatively you can also right click on the webapplication and say Add Library Package Reference.

    By default you will see a list of packages that are installed in your project. To get Telerik Extensions for MVC3 Click Online and type Telerik in the search box

    You can simply hit install button right next to the Package TelerikMVCExtension.MVC3.

    Once you hit install you will see Telerik Scripts (Javascript files) and content(CSS and Image files) automatically added to your application.

    Now all we need to do is add Styles and Register the Telrik Script Registrar in your _Layout.cshtml(Equivalent to masterpage).

    For style links add the following line in the head section of your master page.

        @(Html.Telerik().StyleSheetRegistrar() 
                          .DefaultGroup(group => group 
                              .Add("telerik.common.css") 
                              .Add("telerik.hay.css") 
                              .Combined(true) 
                              .Compress(true)) 
                         ) 

    For registering Telerik Scripts add the following line towards the end of your _Layout.cshtml page.

    @(Html.Telerik().ScriptRegistrar()) 

    That's it. Man doesn't NuGet make adding third party libraries to your application with such ease and awesomeness.?

    You can now use telerik controls in your MVC3 application with the new Razor syntax.

    Hope this helped.

    Cheers,

    Venkata


    Go comment!