mdn_0114dg

Upload: cberscribd

Post on 17-Oct-2015

26 views

Category:

Documents


2 download

TRANSCRIPT

  • 5/27/2018 MDN_0114DG

    1/88

    Create mobile apps with

    HTML5, JavaScript and Visual StudioDevExtreme Mobileis a single page application (SPA) framework for your nextWindows Phone, iOS and Android application, ready for online publication orpackaged as a store-ready native app using Apache Cordova (PhoneGap). WithDevExtreme, you can target todays most popular mobile devices with a singlecodebase and create interactive solutions that will amaze.Get started today

    Leverage your existing Visual Studio expertise.

    Build a real app, not just a web page.

    Deliver a native UI and experience on all supported devices.

    Use over 30 built-in touch optimized widgets.

    devexpress.com/mobileLearn more and download your free trial

    All trademarks or registered trademarks are property of their respective owners.

    magazine

    THE MICROSOFT JOURNAL FOR DEVELOPERS JANUARY 2014 VOL 29 NO 1

    Error-HandlingTechniques in WinJS...........

    http://www.devexpress.com/mobilehttp://www.devexpress.com/mobilehttp://www.devexpress.com/mobilehttp://www.devexpress.com/mobilehttp://www.devexpress.com/mobilehttp://www.devexpress.com/mobilehttp://www.devexpress.com/mobilehttp://www.devexpress.com/mobilehttp://www.devexpress.com/mobilehttp://www.devexpress.com/mobilehttp://www.devexpress.com/mobilehttp://www.devexpress.com/mobilehttp://www.devexpress.com/mobilehttp://www.devexpress.com/mobilehttp://www.devexpress.com/mobilehttp://www.devexpress.com/mobilehttp://www.devexpress.com/mobilehttp://www.devexpress.com/mobilehttp://www.devexpress.com/mobilehttp://www.devexpress.com/mobilehttp://www.devexpress.com/mobilehttp://www.devexpress.com/mobile
  • 5/27/2018 MDN_0114DG

    2/88

    http://www.devexpress.com/mobilehttp://www.devexpress.com/try
  • 5/27/2018 MDN_0114DG

    3/88

    magazine

    THE MICROSOFT JOURNAL FOR DEVELOPERS JANUARY 2014 VOL 29 NO 1

    Build More Efficient Windows Store AppsUsing JavaScript: Error HandlingEric Schmidt. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 22

    Introducing Visual Studio OnlineEd Blankenship. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 32

    Build Fault-Tolerant Composite ApplicationsIvan Krivyakov. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 40

    Create Modern Microfichewith the Chronicling America APITim Kulp. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 50

    Troubleshooting Applications with IIS LogsEduardo Sanabria. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 60

    Unit Testing SQL Server OLAPCubes Using C#Mark Nadelson. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 64

    COLUMNSWINDOWS WITH C++

    Using Regular Expressionswith Modern C++Kenny Kerr 6

    DATA POINTS

    Code First Goodiesin Entity Framework 6Julie Lerman 12

    TEST RUN

    Frequent Item-Sets forAssociation Rule LearningJames McCaffrey 70

    THE WORKINGPROGRAMMER

    Getting Started with Oak:Database InteractionTed Neward 76

    DONT GET ME STARTED

    The Steam DrillDavid Platt 80

    Error-HandlingTechniques in WinJS...........

  • 5/27/2018 MDN_0114DG

    4/88

    http://www.ontimenow.com/MSDN
  • 5/27/2018 MDN_0114DG

    5/88

    http://www.ontimenow.com/MSDN
  • 5/27/2018 MDN_0114DG

    6/88

    "lightning fast" Redmond Magazine

    "covers all data sources" eWeek

    "results in less than a second"InfoWorld

    hundreds more reviews and developercase studies at www.dtsearch.com

    The Smart Choice for Text Retrievalsince 1991

    www.dtSearch.com 1-800-IT-FINDS

    Instantly SearchTerabytes of Text

    Ask about fully-functional evaluations

    25+ fielded and full-text search types

    dtSearchs own document filterssupport Office, PDF, HTML, XML, ZIP,emails (with nested attachments), andmany other file types

    Supports databases as well as staticand dynamic websites

    Highlights hitsin all of the above

    APIs for .NET, Java, C++, SQL, etc.64-bit and 32-bit; Win and Linux

    dtSearch products:

    Desktop with Spider Web with Spider

    Network with Spider Engine for Win &.NETPublish(portable media) Engine for Linux

    Document filters also available for separatelicensing

    Printed in the USA

    magazineJANUARY 2014 VOLUME29NUMBER1

    MOHAMMAD AL-SABTEditorial Director/[email protected]

    KENT SHARKEYSite Manager

    MICHAEL DESMONDEditor in Chief/[email protected]

    DAVID RAMELTechnical Editor

    SHARON TERDEMANFeatures Editor

    WENDY HERNANDEZGroup Managing Editor

    SCOTT SHULTZCreative Director

    JOSHUA GOULDArt Director

    SENIOR CONTRIBUTING EDITORDr. James McCaffreyCONTRIBUTING EDITORSRachel Appel, Dino Esposito, Kenny Kerr,Julie Lerman, Ted Neward, Charles Petzold, David S. Platt,Bruno Terkaly, Ricardo Villalobos

    Henry AllainPresident, Redmond Media Group

    Michele ImgrundSr. Director of Marketing & Audience EngagementTracy CookDirector of Online Marketing

    Irene FincherAudience Development Manager

    ADVERTISING SALES: 818-674-3416/[email protected]

    Dan LaBiancaVice President, Group PublisherChris KourtoglouRegional Sales ManagerDanna VedderRegional Sales Manager/Microsoft Account Manager

    David SeymourDirector, Print & Online ProductionSerena BarnesProduction Coordinator/[email protected]

    Neal VitalePresident & Chief Executive Ofcer

    Richard VitaleSenior Vice President & Chief Financial OfcerMichael J. ValentiExecutive Vice President

    Christopher M. CoatesVice President, Finance & AdministrationErik A. LindgrenVice President, Information Technology & Application Development

    David F. MyersVice President, Event Operations

    Jeffrey S. KleinChairman of the Board

    MSDN Magazine(ISSN 1528-4859) is published monthly by 1105 Media, Inc., 9201 Oakdale Avenue,Ste. 101, Chatsworth, CA 91311. Periodicals postage paid at Chatsworth, CA 91311-9998, and atadditional mailing ofces. Annual subscription rates payable in US funds are: U.S. $35.00, International$60.00. Annual digital subscription rates payable in U.S. funds are: U.S. $25.00, International $25.00.Single copies/back issues: U.S. $10, all others $12. Send orders with payment to: MSDN Magazine,P.O. Box 3167, Carol Stream, IL 60132, email [email protected] orcall (847) 763-9560.POSTMASTER:Send address changes to MSDN Magazine, P.O. Box 2166, Skokie, IL 60076. CanadaPublications Mail Agreement No: 40612608. Return Undeliverable Canadian Addresses to CirculationDept. or XPO Returns: P.O. Box 201, Richmond Hill, ON L4B 4R5, Canada.

    Printed in the U.S.A. Reproductions in whole or part prohibited except by written permission. Mailrequests to Permissions Editor, c/o MSDN Magazine, 4 Venture, Suite 150, Irvine, CA 92618.

    Legal Disclaimer:The information in this magazine has not undergone any formal testing by 1105 Media,

    Inc. and is distributed without any warranty expressed or implied. Implementation or use of any informationcontained herein is the readers sole responsibility. While the information has been reviewed for accuracy,there is no guarantee that the same or similar results may be achieved in all environments. Technicalinaccuracies may result from printing errors and/or new developments in the industry.

    Corporate Address:1105 Media, Inc., 9201 Oakdale Ave., Ste 101, Chatsworth, CA 91311,www.1105media.com

    Media Kits:Direct your Media Kit requests to Matt Morollo, VP Publishing, 508-532-1418 (phone),508-875-6622 (fax), [email protected]

    Reprints:For single article reprints (in minimum quantities of 250-500), e-prints, plaques and posters contact:PARS International, Phone: 212-221-9595, E-mail: [email protected], www.magreprints.com/QuickQuote.asp

    List Rental:This publications subscriber list, as well as other lists from 1105 Media, Inc., is availablefor rental. For more information, please contact our list manager, Jane Long, Merit Direct. Phone: 913-685-1301; E-mail:[email protected]; Web: www.meritdirect.com/1105

    All customer service inquiries should be sent to [email protected] orcall 847-763-9560.

    http://www.dtsearch.com/http://www.dtsearch.com/http://www.dtsearch.com/http://www.dtsearch.com/http://www.dtsearch.com/http://www.dtsearch.com/http://www.dtsearch.com/http://www.dtsearch.com/http://www.dtsearch.com/http://www.dtsearch.com/http://www.dtsearch.com/http://www.dtsearch.com/http://www.dtsearch.com/http://www.dtsearch.com/http://www.dtsearch.com/http://www.dtsearch.com/http://www.dtsearch.com/http://www.dtsearch.com/http://www.dtsearch.com/http://www.dtsearch.com/http://www.dtsearch.com/http://www.dtsearch.com/http://www.dtsearch.com/http://www.dtsearch.com/http://www.dtsearch.com/http://www.dtsearch.com/http://www.dtsearch.com/http://www.dtsearch.com/http://www.dtsearch.com/http://www.dtsearch.com/http://www.dtsearch.com/http://www.dtsearch.com/http://www.dtsearch.com/http://www.dtsearch.com/http://www.dtsearch.com/http://www.dtsearch.com/http://www.dtsearch.com/http://www.dtsearch.com/http://www.dtsearch.com/http://www.dtsearch.com/http://www.dtsearch.com/http://www.dtsearch.com/http://www.dtsearch.com/http://www.dtsearch.com/http://www.dtsearch.com/mailto:[email protected]:[email protected]:818-674-3416/[email protected]:[email protected]:[email protected]:[email protected]://www.1105media.com/mailto:[email protected]:[email protected]://www.magreprints.com/mailto:[email protected]://www.magreprints.com/mailto:[email protected]://www.meritdirect.com/1105mailto:[email protected]:[email protected]://www.meritdirect.com/1105mailto:[email protected]://www.magreprints.com/mailto:[email protected]:[email protected]://www.1105media.com/mailto:[email protected]:[email protected]:818-674-3416/[email protected]:[email protected]:[email protected]://www.dtsearch.com/
  • 5/27/2018 MDN_0114DG

    7/88

    http://www.xceed.com/
  • 5/27/2018 MDN_0114DG

    8/88

    msdn magazine4

    We recently surveyed MSDN Magazine readers and ound that,with the exception o C#, more companies report working withJavaScript than any other programming languagemore than Java,more than C/C++, more than Visual Basic. So it should come asno surprise that this months issue ocuses on JavaScript develop-ment or Windows Runtime.

    In his lead eature, Build More Effi cient Windows Store AppsUsing JavaScript: Error Handling, Eric Schmidt dives into some

    undamental concepts o the Windows Library or JavaScript(WinJS), including promises, asynchronous debugging, and errorhandling. As Schmidt notes in an interview, the tooling and capa-bilities o WinJS differ rom JavaScript in that the environment istailored for full-edged app development, rather than for Web sites.And these differences are important to understand when ensuringthat aws in code and logic are properly handled.

    Many o the techniques Schmidt explores in this months ea-ture are present in the initial version of Windows and WinJS, butSchmidt says many developers are unclear on how the techniqueswork and relate to each other. He wrote this months article withthe idea o explaining how the entire package o error-handlingworks together rom a top-down, holistic perspective.

    For instance, Schmidt describes the JavaScript window.onerror

    event as the catchall or error handling or Web apps. WindowsStore apps built using WinJS, however, leverage both window.onerrorand the WinJS.Application.onerror event handler, which catchesadditional events like platorm-specic errors and promises thaterror out. Schmidt also urges developers to consider moving to

    Visual Studio 2013, which delivers key tooling improvements,including the ability to track down errors within chains oasynchronous callsan important capability given that WinJS appsrequently chain promises to each other.

    When one o those promises errors out, you either need tohave an onError parameter or each promise in the chain, or youneed to track down the error starting rom the last promise in thechain, explains S chmidt, who says both approaches are time con-

    suming. Te asks pane, which has been extended to encompassJavaScript code in Visual Studio 2013, really helps developers trackdown those errors in their code, he notes.

    Te latest version of WinJS and its attendant tooling deliver whatSchmidt describes as ready to go templates and controls that helpstreamline development. Te updates also deliver signicant per-formance improvements and streamlined WinJS app development.

    We provided new tools in Visual Studio 2013 or measuringHML UI responsiveness, JavaScript memory usage, JavaScriptunction timing and asynchronous debugging, Schmidt says. Inthe platorm, we improved the perormance o some o our existingcontrolsor example, ListViewwith APIs like the Dispose

    pattern and the Scheduler, as well as provided new controls that arebetter suited for specic tasksfor example, the Repeater control.

    Speaking o perormance improvements, next month Schmidtwill publish a follow-on article focused specically on performanceissues. What advice does he have or developers struggling toensure that their WinJS applications are perormant?

    Te No. 1 thing Id recommend is to really use the platorm. Anyretained-mode systemwhether its HML or XAML or PDF or youname ithas certain sets of capabilities that are natively implementedand highly optimized within it. In as much as your app code and scriptcalls into and leverages those capabilities, the better performance youllget, Schmidt says. He adds that the latest version of WinJS pushes more

    o the eatures lower down into the implementation, where they canbe optimized or best perormance.

    Are you working with WinJS? I so, Id love to hear about yourexperience. E-mail me [email protected].

    WinJS Takes the Next Step

    2014 Microsoft Corporation. All rights reserved.

    Complying with all applicable copyright laws is the responsibility of the user. Without limiting the rights under copyright, you are not permitted to reproduce, store, or introduce into a retrieval system MSDN Magazineor any part of MSDNMagazine. If you have purchased or have otherwise properly acquired a copy of MSDN Magazinein paper format, you are permitted to physically transfer this paper copy in unmodied form. Otherwise, you are not permitted to transmitcopies of MSDN Magazine(or any part of MSDN Magazine) in any form or by any means without the express written permission of Microsoft Corporation.

    A listing of Microsoft Corporation trademarks can be found at microsoft.com/library/toolbar/3.0/trademarks/en-us.mspx. Other trademarks or trade names mentioned herein are the property of their respective owners.

    MSDN Magazineis published by 1105 Media, Inc. 1105 Media, Inc. is an independent company not afliated with Microsoft Corporation. Microsoft Corporation is solely responsible for the editorial contents of this magazine. Therecommendations and technical guidelines in MSDN Magazine are based on specic environments and congurations. These recommendations or guidelines may not apply to dissimilar congurations. Microsoft Corporation does not make

    any representation or warranty, express or implied, with respect to any code or other information herein and disclaims any liability whatsoever for any use of such code or other information.MSDN Magazine, MSDN, and Microsoft logos areused by 1105 Media, Inc. under license from owner.

    Visit us atmsdn.microsoft.com/magazine. Questions, comments or suggestions for MSDN Magazine? Send them to the editor: [email protected].

    MICHAEL DESMONDEDITORSNOTE

    Schmidt describes the JavaScript

    window.onerror event as

    the catchall for error handlingfor Web apps.

    http://www.xceed.com/http://msdn.microsoft.com/magazinemailto:[email protected]://msdn.microsoft.com/magazinemailto:[email protected]
  • 5/27/2018 MDN_0114DG

    9/88

    MAXIMUM FLEXIBILITY FOR YOUR WEB PROJECTS

    Maximum Availability (Geo-redundancy)300 Gbit/s network connection2 GB RAM guaranteedNEW: Maximum performance with

    1&1 CDN powered by CloudFlare

    NEW: SiteLock security scan included!

    STATE-OF-THE-ART TECHNOLOGY

    1&1 Search Engine OptimizationListing in business directories1&1 E-Mail Marketing ManagerFacebookCredits

    SUCCESSFUL MARKETING

    Premium software, including

    AdobeDreamweaverCS5.5,

    and NetObjects Fusion20131&1 Mobile Website BuilderNEW: PHP 5.5, Perl, Python, Ruby

    POWERFUL TOOLS

    POWERFUL APPS

    Over 140 popular apps (Drupal, WordPress,

    Joomla!, Typo3, Magentoand many more...)App Expert Support to answer your questions

    Included Domains: .com, .net, .org, .biz, .infoUnlimited Power: webspace, traffic, mail accounts, SQL databasesLinux or Windows operating system

    ALL INCLUSIVE

    HOSTINGNEW

    1and1.com

    TRIAL30 DAY MONEY

    BACK GUARANTEE

    MONTHFLEXIBLE PAYMENT

    OPTIONS

    CALLSPEAK WITH AN

    EXPERT 24/7

    HOSTING PACKAGES

    FOR PROFESSIONALS

    STARTING AT

    Call1 (877) 461-2631

    $0.99

    per mont

    *Offer valid for a limited time only. The $0.99/month price reflect s a 12-month pre-payment option for the 1&1 Starter Hosting package. Regular price of $2.99/month after 12 months.

    Some features listed are only available with package upgrade. (Visit www.1and1.com for full details.) Program and pricing specifications and availability subject to change without notice.

    1&1 and the 1&1 logo are trademarks of 1&1 Internet, all other trademarks are the property of their respective owners. 2014 1&1 Internet. All rights reserved.

    http://www.1and1.com/http://www.1and1.com/http://www.1and1.com/http://www.1and1.com/http://www.1and1.com/http://www.1and1.com/http://www.1and1.com/http://www.1and1.com/http://www.1and1.com/http://www.1and1.com/http://www.1and1.com/http://www.1and1.com/http://www.1and1.com/http://www.1and1.com/http://www.1and1.com/http://www.1and1.com/http://www.1and1.com/http://www.1and1.com/http://www.1and1.com/http://www.1and1.com/http://www.1and1.com/http://www.1and1.com/http://www.1and1.com/http://www.1and1.com/http://www.1and1.com/http://www.1and1.com/http://www.1and1.com/http://www.1and1.com/http://www.1and1.com/http://www.1and1.com/http://www.1and1.com/http://www.1and1.com/http://www.1and1.com/http://www.1and1.com/http://www.1and1.com/http://www.1and1.com/http://www.1and1.com/http://www.1and1.com/http://www.1and1.com/http://www.1and1.com/http://www.1and1.com/http://www.1and1.com/http://www.1and1.com/http://www.1and1.com/http://www.1and1.com/http://www.1and1.com/http://www.1and1.com/http://www.1and1.com/http://www.1and1.com/http://www.1and1.com/http://www.1and1.com/http://www.1and1.com/http://www.1and1.com/http://www.1and1.com/http://www.1and1.com/http://www.1and1.com/http://www.1and1.com/http://www.1and1.com/http://www.1and1.com/http://www.1and1.com/http://www.1and1.com/http://www.1and1.com/http://www.1and1.com/http://www.1and1.com/http://www.1and1.com/http://www.1and1.com/http://www.1and1.com/http://www.1and1.com/http://www.1and1.com/http://www.1and1.com/http://www.1and1.com/http://www.1and1.com/http://www.1and1.com/http://www.1and1.com/http://www.1and1.com/http://www.1and1.com/http://www.1and1.com/http://www.1and1.com/http://www.1and1.com/http://www.1and1.com/http://www.1and1.com/http://www.1and1.com/http://www.1and1.com/http://www.1and1.com/http://www.1and1.com/http://www.1and1.com/http://www.1and1.com/http://www.1and1.com/http://www.1and1.com/http://www.1and1.com/http://www.1and1.com/http://www.1and1.com/http://www.1and1.com/http://www.1and1.com/http://www.1and1.com/http://www.1and1.com/http://www.1and1.com/http://www.1and1.com/http://www.1and1.com/http://www.1and1.com/http://www.1and1.com/http://www.1and1.com/http://www.1and1.com/http://www.1and1.com/http://www.1and1.com/http://www.1and1.com/http://www.1and1.com/http://www.1and1.com/http://www.1and1.com/
  • 5/27/2018 MDN_0114DG

    10/88

    msdn magazine6

    C++ is a language for developing and using elegant and effi cientabstractions.Bjarne Stroustrup

    Tis quote from the creator of C++ really sums up what I loveabout the language. I get to develop elegant solutions to my prob-lems by combining the language features and programming stylesthat I deem most suitable to the task.

    C++ introduced a long list of features that are in themselves quiteexciting, but if all you see is a list of isolated features, then youremissing out. Te combination of these features makes C++ into

    the powerhouse that many have grown to appreciate. Im going toillustrate this point by showing you how to use regular expressionswith modern C++. Te C++ standard introduced a powerfulregular expression library, but if you use it in isolationusing atraditional C++ programming styleyou might nd it somewhattiresome. Unfortunately, this is the way that most of the C++libraries tend to be introduced. However, there is some merit insuch an approach. If you were looking for a concise example ofusing some new library, it would be rather overwhelming to beforced into comprehending a slew of new language features at thesame time. Still, the combination of C++ language and librar y fea-tures really turns C++ into a productive programming language.

    o keep the examples focused on C++ and not on regular expres-sions, Im necessarily going to use very simplistic patterns. You mightwonder why Im using regular expressions for such trivial problems,but it helps avoid getting lost in the mechanics of expression pro-cessing. Heres a simple example: Id like to match strings of nameswhere the names might be formatted Kenny Kerr or Kerr, Kenny.I need to identify the rst name and family name and then printthem out in some consistent manner. First up is the target string:

    char const s[] = "Kerr, Kenny";

    o keep things simple ,Ill stick to char strings and Ill avoid usingthe standard librarys basic_string class except to i llustrate theresults of certain matches. Teres nothing wrong with basic_string,

    but I nd that most of the work I do with regular expressions tendsto be targeted at memory-mapped les. Copying the contents ofthese les into string objects would only serve to slow down myapplications. Te standard librarys regular expression support isindifferent and perfectly happy to process sequences of characterswithout concern for how theyre managed.

    Te next thing Ill need is a match object:auto m = cmatch {};

    Tis is really a collection of matches. Te cmatch is a match_resultsclass template thats been specialized for char strings. At this point,the match collection is empty:

    ASSERT(m.empty());

    Ill also need a pair of strings to receive the results:string name, family;

    I can now call the regex_match function:if (regex_match(s, m, regex { R"((\w+) (\w+))" })){}

    Tis function attempts to match the pattern against the entirecharacter sequence. Tis is in contrast to the regex_search functionthats quite happy to search for a match at any point within the string.Im just creating the regex object inline for brevity, but this is notwithout cost. If you were going to match this regular expressionrepeatedly, you might be better off creating the regex object onceand then holding on to it for the life of your application. Te pre-ceding pattern matches the names using the Kenny Kerr format.Assuming its a match, I can just copy out the substrings:

    name = m[1].str();family = m[2].str();

    Te subscript operator returns the specied sub_match object.An index of zero represents the match as a whole, while subsequentindexes pinpoint any groups identied in the regular expression.Neither the match_results nor the sub_match object will create orallocate a substring. Instead, they delineate the range of characterswith a pointer or iterator to the beginning and end of the matchor submatch, producing the usual half-open range favored by thestandard library. In this case, Im explicitly calling the str method on

    each sub_match to create a copy of each submatch as string objects.Tat handles the rst possible format. For the second I need another

    call to regex_match with the alternative pattern (technically, you couldmatch both formats with a single expression, but thats beside the point):

    else if (regex_match(s, m, regex { R"((\w+), (\w+))" })){ name = m[2].str(); family = m[1].str();}

    Tis pattern matches the names using the Kerr, Kenny format.Notice that Ive had to reverse the indices, as the rst group repre-sented in this regular expression identies the family name while thesecond identies the rst name. Tats about it for the regex_match

    function. Figure 1provides the complete listing for reference.I dont know about you, but the code inFigure 1looks tedious

    to me. While the regular expression library is certainly powerfuland flexible, its not particularly elegant. I need to know aboutmatch_results and sub_match objects. I need to remember howthis collection is indexed and how to extract the results. I couldavoid making the copies, but it quickly becomes onerous.

    Ive already used a number of new C++ language features thatyou may or may not have come across before, but nothing shouldbe overly startling. Now I want to show how you can use variadictemplates to really spice up your regular expression usage. Ratherthan diving right in with more language features, Im going to start

    by showing you a simple abstraction to simplify text processing soI can keep this practical and elegant.

    Using Regular Expressions with Modern C++

    WINDOWSWITHC++ KENNY KERR

    http://www.1and1.com/
  • 5/27/2018 MDN_0114DG

    11/88

    http://www.amyuni.com/
  • 5/27/2018 MDN_0114DG

    12/88

    msdn magazine8 Windows with C++

    First, Ill dene a simple type to represent a sequence of charactersthat arent necessarily null-terminated. Heres the strip class:

    struct strip{ char const * first; char const * last;

    strip(char const * const begin, char const * const end) : first { begin }, last { end } {}

    strip() : strip { nullptr, nullptr } {}};

    Tere are undoubtedly numerous such classes that I might reuse,but I nd it helps to avoid too many dependencies when producingsimple abstractions.

    Te strip class doesnt do much, but Ill augment it with a set ononmember unctions. Ill start with a pair o unctions to denethe range generically:

    auto begin(strip const & s) -> char const *

    { return s.first;}

    auto end(strip const & s) -> char const *{ return s.last;}

    Although not strictly necessary to this example, I nd this tech-nique provides a worthy measure of consistency with the standardlibrarys containers and algorithms. Ill get back to the begin and endfunctions in a moment. Up next is the make_strip helper function:

    template auto make_strip(char const (&text)[Count]) -> strip{ return strip { text, text + Count - 1 };

    }

    Tis unction comes in handy when attempting to create a striprom a string literal. For example, I can initialize a strip as ollows:

    auto s = make_strip("Kerr, Kenny");

    Next, its ofen useul to determine the length or size o the strip:auto size(strip const & s) -> unsigned{ return end(s) - begin(s);}

    Here you can see Im simply reusing the begin and end functionsto avoid a dependency on the strips members. I could protect themembers o the strip class. On the other hand, its ofen helpul to

    be able to manipulate them directly from within an algorithm. Still,i I dont need to take a hard dependency, I wont.

    Obviously, its simple enough to create a standard string from a strip:auto to_string(strip const & s) -> string{ return string { begin(s), end(s) };}

    Tis might come in handy if some of the results outlive the orig-inal character sequences. Tat rounds out the basic strip handling.I can initialize a strip and determine its sizeand thanks to thebegin and end unctions, I can use a range-or statement to iterateover its characters:

    auto s = make_strip("Kenny Kerr");

    for (auto c : s){ printf("%c\n", c);}

    When I rst wrote the strip class, I was hoping I could call itsmembers begin and end instead of rst and last. Te trouble isthat the compiler, when confronted with a range-for statement, rstattempts to nd suitable members that may be called as unctions.If the target range or sequence doesnt include any members calledbegin and end, then the compiler looks or a suitable pair in theenclosing scope. Te trouble is that i the compiler nds memberscalled begin and end but they arent suitable, it wont attempt to lookany urther. Tis might seem shortsighted, but C++ has complexname-lookup rules, and anything else would make it even moreconusing and inconsistent.

    Te strip class is a simple little construct, but it doesnt do muchin itsel. Ill now combine it with the regular expression library toproduce an elegant abstraction. I want to hide the mechanics of thematch object, the tedious part of expression processing. Tis is wherevariadic templates come in. Te key to understanding variadic tem-plates is realizing you can separate the rst argument rom the rest.Tis typically results in compile-time recursion. I can dene a vari-adic template to unpack a match object into subsequent arguments:

    template auto unpack(cmatch const & m, Args & ... args) -> void{ unpack(m, args...);}

    Te typename... indicates that Args is a template parameterpack. Te corresponding ... in the type o args indicates that argsis a unction parameter pack. Te sizeo... expression determines

    the number o elements in the parameter pack. he inal ...following args tells the compiler to expand the parameter pack intoits sequence o elements.

    Te type of each argument may be different, but in this case, eachwill be a non-const strip reference. Im using a variadic template so anunknown number of arguments can be supported. So far the unpackunction doesnt appear to be recursive. It orwards its argumentsto another unpack unction with an additional template argument:

    template auto unpack(cmatch const & m, strip & s, Args & ... args) -> void{ auto const & v = m[Total - sizeof...(Args)]; s = { v.first, v.second }; unpack(m, args...);}

    char const s[] = "Kerr, Kenny";auto m = cmatch {};string name, family;

    if (regex_match(s, m, regex { R"((\w+) (\w+))" })){ name = m[1].str(); family = m[2].str();}else if (regex_match(s, m, regex { R"((\w+), (\w+))" })){ name = m[2].str(); family = m[1].str();}else{

    printf("No match\n");}

    Figure 1 The regex_match Reference Example

  • 5/27/2018 MDN_0114DG

    13/88

    9January 2014msdnmagazine.com

    However, this unpack function separates t he first argumentfollowing the match object from t he rest. hats compile-timerecursion in action. Assuming the args parameter pack isnt empty,it calls itsel with the rest o the arguments. Eventually the sequenceof arguments becomes empty and a third unpack function is needed

    to deal with this conclusion:template auto unpack(cmatch const &) -> void {}

    Tis function doesnt do anything. It merely acknowledges thefact that the parameter pack may be empty. Te previous unpackfunctions hold the key to unpacking the match object. Te rstunpack function captured the original number of elements in theparameter pack. Tis is necessary because each recursive call willeffectively produce a new parameter pack with a diminishing size.Notice how Im subtracting the size o the parameter pack rom theoriginal total. Given this total or stable size, I can index into thematch collection to retrieve the individual submatches and copytheir respective bounds into the variadic arguments.

    Tat takes care of unpacking the match object. Although notrequired, I still nd it helpful to hide the match object itself if itisnt needed directlyfor example, if its only needed to access thematch prex and suffi x. Ill wrap up the whole thing to provide asimpler match abstraction:

    template auto match(strip const & s, regex const & r, Args & ... args) -> bool{ auto m = cmatch {};

    if (regex_match(begin(s), end(s), m, r)) { unpack(m, args...);

    }

    return !m.empty();}

    Tis unction is also a variadic template but isnt in itsel recursive.It merely forwards its arguments to the original unpack functionfor processing. It also takes care of providing a local match objectand dening the search sequence in terms of strips begin and endhelper functions. An almost identical function can be written toaccommodate regex_search instead of regex_match. I can nowrewrite the example fromFigure 1far more simply:

    auto const s = make_strip("Kerr, Kenny");strip name, family;

    if (match(s, regex { R"((\w+) (\w+))" }, name, family) || match(s, regex { R"((\w+), (\w+))" }, family, name)){ printf("Match!\n");}

    How about iteration? Te unpack unctions also come in handyfor handling the match results of an iterative search. Imagine astring with the canonical Hello world in a variety of languages:

    auto const s =make_strip("Hello world/Hola mundo/Hallo wereld/Ciao mondo");

    I can match each one with the following regular expression:auto const r = regex { R"((\w+) (\w+))" };

    he regular expression library provides the regex_iteratorto iterate through the matches, but using iterators directly can

    become tedious. One option is to write a for_each function thatcalls a predicate for each match:

    template auto for_each(strip const & s, regex const & r, F callback) -> void{ for (auto i = cregex_iterator { begin(s), end(s), r }; i != cregex_iterator {}; ++i)

    { callback(*i); }}

    I could then call this function with a lambda expression tounpack each match:

    for_each(s, r, [] (cmatch const & m){ strip hello, world; unpack(m, hello, world);});

    Tis certainly works, but I always nd it frustrating that I canteasily break out of this type of loop construct. he range-forstatement provides a more convenient alternative. Ill begin by

    dening a simple iterator range that the compiler will recognize toimplement the range-for loop:template struct iterator_range{ T first, last;

    auto begin() const -> T { return first; } auto end() const -> T { return last; }};

    I can now write a simpler for_each function that just returnsan iterator_range:

    auto for_each(strip const & s, regex const & r) -> iterator_range{ return

    { cregex_iterator { begin(s), end(s), r }, cregex_iterator {} };}

    he compiler will take care of producing the iteration and Ican simply write a range-for statement with minimal syntacticoverhead, breaking early if I so choose:

    for (auto const & m : for_each(s, r)){ strip hello, world; unpack(m, hello, world);

    printf("'%.*s' '%.*s'\n", size(hello), begin(hello), size(world), begin(world));

    }Te console presents the expected results:'Hello' 'world''Hola' 'mundo''Hallo' 'wereld''Ciao' 'mondo'

    C++ and beyond provide an opportunity to revitalize C++sofware development with a modern style o programming that letsyou produce elegant and effi cient abstractions. Te regular expres-sion grammar can humble even the most seasoned of developers.Why not spend a ew minutes developing a more elegant abstraction?At least the C++ portion of your task will be a pleasure!

    KENNYKERRis a computer programmer based in Canada, an author or

    Pluralsight and a Microsof MVP. He blogs at kennykerr.ca and you can ollowhim on Twitter at twitter.com/kennykerr.

    http://www.msdnmagazine.com/http://www.twitter.com/kennykerrhttp://www.twitter.com/kennykerrhttp://www.msdnmagazine.com/
  • 5/27/2018 MDN_0114DG

    14/88

    mailto:[email protected]:[email protected]://www.aspose.com/
  • 5/27/2018 MDN_0114DG

    15/88

    http://www.aspose.com/
  • 5/27/2018 MDN_0114DG

    16/88

    msdn magazine12

    In my December article, Entity Framework : Te Ninja Edition(msdn.microsoft.com/magazine/dn532202 ), I described many of the new fea-tures in Entity Framework (EF). I wasnt able to delve into everyfeature, though, so this month Ill drill into some of the EF enhance-ments specic to Code First. wo of the features Ill discuss are relevantto Code First mappings, and the others relate to Code First migrations.

    Load Many Fluent API Mappings at OnceTere are two ways to specify Fluent mappings (from your classesto your database) for a model. One is directly in the OnModel-Creating method of the DbContext class, like this:

    modelBuilder.Entity() .Property(c=>c.Name).IsRequired().HasMaxLength(200);modelBuilder.Entity() .Property(c => c.SerialNo).HasColumnName("SerialNumber");

    When you have a lot of mappings, you can organize them bytype into individual EntityypeConguration classes, which youthen add into the model builder using code like this:

    modelBuilder.Configurations.Add(new CasinoConfiguration());

    modelBuilder.Configurations.Add(new PokerTableConfiguration());

    However, if you have a lot of mappings for a lot of entities, youcan end up with many repetitive modelBuilder.Congurations.Addmethods in OnModelCreating. o eliminate this drudgery, youcan now load all EntityypeCongurations from a given assemblywith a single method. Here I use the new AddFromAssemblymethod to load congurations that are specied in the executingassembly for the running application:

    modelBuilder.Configurations .AddFromAssembly(Assembly.GetExecutingAssembly())

    A nice feature of this method is that it isnt restricted by thescope of the configur ations it will load. he custom Entityype-Conguration classes can even be marked private and the methodwill nd them. Moreover, AddFromAssembly also comprehendsinheritance hierarchies in EntityypeCongurations.

    AddFromAssembly is one of a number of community contri-butions from Unai Zorrilla. See Zorrillas blog post, EF: SettingCongurations Automatically, at bit.ly/16OBuJ5for more detailsandleave him a note of thanks while youre there.

    Define Your Own Default SchemaIn my March Data Points column, Playing with the EF Alpha(msdn.microsoft.com/magazine/jj991973 ), I talked a bit about schema

    support for Code First. One new feature is a mapping you cancongure in OnModelCreating: HasDefaultSchema. Tis lets youspecify the database schema for all of the tables a context maps to,rather than using the EF default of dbo. In the Entity Framework :Te Ninja Edition article, I executed some raw SQL in the discus-sion about Dbransactions:

    ("Update Casino.Casinos set rating= " + (int) Casino.Rating)

    You may have noticed the Casino schema I specied in the SQL. Tereason I have a schema named Casino is because I specied it in theOnModelCreating method of my DbContext (CasinoSlotsModel):

    modelBuilder.HasDefaultSchema("Casino");

    I also talked about the new support in EF for Code Firstmigrations that are being run against a database that has differentschemas in it. Because that hasnt changed since EF Alpha, Ill letyou read about it in my earlier column.

    Migrations Scripts to Rebuild the

    Database from Any PointOne of the new features for Code First migrations listed in the specs(and in every article that simply reiterates the specs) is idempotentmigrations scripts. Now, you may be someone with a comp scidegree under your belt, or perhaps youre a DBA. But I am neither andI had to look up the meaning of idempotent. According to Wikipedia,which references an IBM engineer (bit.ly/9MIrRK): In computer science,the term idempotent is used to describe an operation that willproduce the same results if executed once or multiple times. I alsohad to look up how to pronounce it. Its eye-dem-poe-tent.

    In the database world, idempotent can be used to describe a SQLscript that always has the same impact on a database regardless ofits state. With Code First migrations, before running a migration,such a script will check to see if that migration has already been run.Tis feature is specic to the -script parameter of Update-Database.

    Code First Goodies in Entity Framework 6

    DATAPOINTS JULIE LERMAN

    Code download available at msdn.microsoft.com/magazine/msdnmag0114.

    Figure1Default Schema for the __MigrationHistory Table

    http://msdn.microsoft.com/magazine/dn532202http://msdn.microsoft.com/magazine/dn532202http://msdn.microsoft.com/magazine/dn532202http://www.bit.ly/16OBuJ5http://www.bit.ly/16OBuJ5http://www.bit.ly/16OBuJ5http://msdn.microsoft.com/magazine/jj991973http://msdn.microsoft.com/magazine/jj991973http://msdn.microsoft.com/magazine/jj991973http://www.bit.ly/9MIrRKhttp://www.bit.ly/9MIrRKhttp://www.bit.ly/9MIrRKhttp://msdn.microsoft.com/magazine/msdnmag0114http://www.bit.ly/9MIrRKhttp://msdn.microsoft.com/magazine/jj991973http://www.bit.ly/16OBuJ5http://msdn.microsoft.com/magazine/dn532202http://msdn.microsoft.com/magazine/msdnmag0114
  • 5/27/2018 MDN_0114DG

    17/88

    DevExpress .NET controls, frameworks and libraries were built with you in mind. Built for those whodemand the highest quality and expect the best performance for those who require reliable toolsengineered to meet todays needs and address tomorrows requirements.

    Experience the DevExpress Difference today and download your free 30-day trial andlets build great apps, together.

    Windows. Web. Mobile.Your next great app starts here.

    Learn more and download your free trial

    devexpress.com/try

    All trademarks or registered trademarks are property of their respective owners.

    http://www.devexpress.com/tryhttp://www.devexpress.com/tryhttp://www.devexpress.com/tryhttp://www.devexpress.com/tryhttp://www.devexpress.com/tryhttp://www.devexpress.com/tryhttp://www.devexpress.com/tryhttp://www.devexpress.com/tryhttp://www.devexpress.com/tryhttp://www.devexpress.com/tryhttp://www.devexpress.com/try
  • 5/27/2018 MDN_0114DG

    18/88

    msdn magazine14 Data Points

    EF has always provided the ability to create scripts that runthrough all of the migration steps from a particular starting point(source) and optionally to an explicit endpoint (target). Tis NuGetcommand evokes that behavior:

    Update-Database -Script SourceMigration:NameOfStartMigration TargetMigration:NameOfEndMigrationThatIsntLatest

    Whats new is that the generated script is much smarter nowwhen you call the command in a particular way:

    Update-Database -Script -SourceMigration $InitialDatabase

    Tis also happens to work if you replace InitialDatabase with, though theres no guarantee this alternative will be supportedin future versions.

    In response, the script starts with the initial migration and carriesthrough to the latest migration. his is why the s yntax does notexplicitly supply the names of the target or source migrations.

    But with this particular command, EF adds logic to the scriptthat checks to see which migrations have already been appliedbefore executing t he SQL for a particul ar migration. Heres anexample of code youll see in the script:

    IF @CurrentMigration < '201310311821192_AddedSomeNewPropertyToCasino'BEGIN ALTER TABLE [Casino].[Casinos] ADD [AgainSomeNewProperty] [nvarchar](4000) INSERT [Casino].[__MigrationHistory]([MigrationId], [ContextKey],[Model], [ProductVersion]) VALUES (N'201310311821192_AddedSomeNewPropertyToCasino', N'CasinoModel.Migrations.Configuration', HugeBinaryValue , N'6.1.0-alpha1-21011')END

    he code checks in t he _MigrationHistory table to s ee if t heAddedSomeNewPropertyoCasino script has been run on thedatabase yet. If it has, the SQL from that migration wont be exe-cuted. Prior to EF, the script would just run the SQL withoutchecking to see if it had already been run.

    Provider-Friendly Migration History TablesEF lets you customize how the _MigrationHistory table isdened using a feature called the Customizable Migrations Historyable. his is important if youreusing third-party data providers thathave different requirements than thedefaults. Figure 1shows the defaultschema of the table.

    Heres an example of how this canbe useful. On CodePlex, a developernoted that because each char in thetwo PKs can be greater than byte, he

    was getting an error that the lengthof the compound key created fromMigrationId and ContextKey exceededthe allowed key length for a MySQLtable: bytes(bit.ly/18rw1BX ). oresolve the issue, the MySQL team isusing the HistoryContext internallyto alter the lengths of the two keycolumns while working on the EFvers ion of MySQL Connector forADO.NE(bit.ly/7uYw2a).

    Notice in Figure 1 that the

    __MigrationHistory table gets thesame schema I dened for the context

    public class CustomHistoryContext : HistoryContext{ public CustomHistoryContext (DbConnection dbConnection, string defaultSchema) : base(dbConnection, defaultSchema)

    { }protected override void OnModelCreating(DbModelBuilder modelBuilder)

    { base.OnModelCreating(modelBuilder); modelBuilder.Entity() .ToTable("__MigrationHistory", "admin"); }}

    Figure 2Custom HistoryContext

    to Redefine __MigrationHistory TableCreateTable( Casino.SlotMachines", c => new { Id = c.Int(nullable: false, identity: true), SlotMachineType = c.Int(nullable: false),

    SerialNumber = c.String(maxLength: 4000), HotelId = c.Int(nullable: false), DateInService = c.DateTime(nullable: false), HasQuietMode = c.Boolean(nullable: false), LastMaintenance = c.DateTime(nullable: false), Casino_Id = c.Int(), }) .PrimaryKey(t => t.Id) .ForeignKey("Casino.Casinos", t => t.Casino_Id) .Index(t => t.Casino_Id);

    Figure4DbMigrations.CreateTable Method

    Figure 3 Customized __MigrationHistory Table

    Figure 5 DbMigrations

    Database SchemaOperations

    With this particular command,

    EF adds logic to the script that

    checks to see which migrationshave already been applied

    before executing the SQL for a

    particular migration.

    http://www.devexpress.com/tryhttp://www.bit.ly/18rw1BXhttp://www.bit.ly/18rw1BXhttp://www.bit.ly/18rw1BXhttp://www.bit.ly/7uYw2ahttp://www.bit.ly/7uYw2ahttp://www.bit.ly/7uYw2ahttp://www.bit.ly/7uYw2ahttp://www.bit.ly/18rw1BX
  • 5/27/2018 MDN_0114DG

    19/88

    15January 2014msdnmagazine.com

    using HasSchema: Casino. You may have conventions that saynon-data tables should be used by a schema with limited permis-sions, so you might want to change the schema name of that table.You can do that with the HistoryContext, for example to specifythat the admin schema be used.

    HistoryContext derives from DbContext, so the code should

    be somewhat familiar if youve worked with DbContext and CodeFirst in the past. Figure 2shows a HistoryContext class I denedto specify the admin schema.

    You can also use familiar API calls likeProperty().HasColumnype, HasMaxLengthor HasColumnName. For example, if youneed to change the length of the ContextKey,you can do this:

    modelBuilder.Entity()

    .Property(h => h.ContextKey).HasMaxLength(255);

    If youve already read last months arti-cle, you should be familiar with EFDbConguration. Tis is what you use to letyour model know about the CustomHistory-

    Context le. In your custom DbCongura-tions constructor, you need to specify theHistoryContext to be used. Here I set thecontext for the SQL Server provider to useCustomHistoryContext:

    SetHistoryContext(

    SqlProviderServices.ProviderInvariantName,

    (connection, defaultSchema) =>

    new CustomHistoryContext(connection,

    defaultSchema));

    Database initialization and migrationsfunctionality will see this additional contextand construct SQL accordingly. The table

    inFigure 3

    was created using the customHistoryContext to change the schema nameof the __MigrationHistory table to admin. (Ididnt include the sample code for changingthe column length.)

    HistoryContext is a powerful feature butit needs to be used carefully. Hopefully thedatabase provider youre using will havealready used it to specify a __MigrationHistorytable thats relevant to the target database,and you wont even need to think aboutthis. Otherwise, I recommend checking

    the MSDN document on this feature andheeding its guidance(bit.ly/16eK2pD).

    Create Custom Migration OperationsIf youve used migrations beforenot automatically but by explicitlycreating and executing migrations f rom the Package ManagerConsole windowyou may have explored the migration les createdby add-migration. If so, you might have discovered that Code Firstmigrations have a strongly typed API to describe each change to make

    to the database schema: System.Data.Entity.Migrations.DbMigration.Figure 4shows an example of the CreateTable method that sets

    a number of attributes.

    HistoryContextis a powerful feature

    but it needs to be

    used carefully.

    http://www.msdnmagazine.com/http://www.bit.ly/16eK2pDhttp://www.bit.ly/16eK2pDhttp://www.bit.ly/16eK2pDhttp://www.bit.ly/16eK2pDhttp://www.softfluent.com/mailto:[email protected]://www.softfluent.com/http://www.softfluent.com/forms/msdn-2014http://www.msdnmagazine.com/
  • 5/27/2018 MDN_0114DG

    20/88

    msdn magazine16 Data Points

    Providers then translate those API calls into database-specic SQL.Tere are methods to create tables and indexes, create or alter prop-

    erties, drop objects and more. Its a fairly rich API, as you can see fromthe possibilities listed inFigure 5which include the ability to simplyexecute some SQL directly. But, in some cases, it may not be richenough or your needs. For example, theres no method or creatingdatabase views, speciying permissions or plenty other operations.

    Once again, the community came to the rescue. In EF, you

    now have the ability to create custom migrations operationsyou can cal l by cus tomizing the migration cla sses gene rate d

    by add-migration. his is thanks to another developer in theCodePlex community, Iaki Elcoro, aka iceclow.

    o create your own operation, you have to perorm a ew steps.Ill show the core o each step. You can see the ull code and howthe steps are organized in the download or this article.

    . Dene the operation. Here Ive dened a CreateView-Operation, as listed in Figure 6.

    . Create an extension method to point to the operation. Tismakes it simple to call rom DbMigration:

    public static void CreateView(this DbMigration migration,

    string viewName, string viewqueryString){ ((IDbMigration) migration) .AddOperation(new CreateViewOperation(viewName, viewqueryString));}

    . Dene the SQL or the operation in the Generate methodo a custom S qlServerMigrationSqlGenerator class, asshown in Figure 7.

    . ell the DbConguration class to use the customSqlServerMigrationSqlGenerator class:

    SetMigrationSqlGenerator("System.Data.SqlClient", () => new CustomSqlServerMigrationSqlGenerator());

    With all o this in place, you can now use the new operation ina migration le and Update-Database will know what to do withit. Figure 8shows the CreateView operation in use, and providesa reminder that youll also need to create an operation to removethe view, which would be called by the Down method i you needto unwind this migration.

    Afer I call Update-Database, you can see the new view in mydatabase in Figure 9.

    Code First Continues to Evolve

    With the core eatures o Code First in place, Microsot anddevelopers rom the community took the opportunity to startputting some polish on EF, with eatures that now benet rommore lexibility. But it doesnt stop with the release o EF. Iyou lter the CodePlex work items or versions beyond .. (atbit.ly/1dA0LZf),you can see that even more polish is being added touture releases o EF and Code First. Tese items are in variousstates. Perhaps youll nd one on which youd like to work.

    JULIELERMANis a Microsof MVP, .NET mentor and consultant who lives in thehills o Vermont. You can nd her presenting on data access and other Microsof.NET topics at u ser groups and conerences around the world. She blogs atthedataarm.com/blog and is the author o Programming Entity Framework() as well as a Code First edition () and a DbContext edition (), allrom OReilly Media. Follow her on Twitter attwitter.com/julielerman and seeher Pluralsight courses at juliel.me/PS-Videos.

    THANKSto the following technical expert for reviewing this article:

    Rowan Miller (Microsof)

    public class CreateViewOperation : MigrationOperation{ public CreateViewOperation(string viewName, string viewQueryString) : base(null) {

    ViewName = viewName; ViewString = viewQueryString; }public string ViewName { get; private set; }

    public string ViewString { get; private set; }public override bool IsDestructiveChange

    { get { return false; } }}

    Figure6A Custom Migration Operation

    for Creating a Database View

    public class CustomSqlServerMigrationSqlGenerator: SqlServerMigrationSqlGenerator

    { protected override void Generate(MigrationOperation migrationOperation) { var operation = migrationOperation as CreateViewOperation;

    if (operation != null) { using (IndentedTextWriter writer = Writer()) { writer.WriteLine("CREATE VIEW {0} AS {1} ; ", operation.ViewName, operation.ViewString); Statement(writer); } } }}

    Figure 7 Custom SqlServerMigrationSqlGenerator Class

    public partial class AddView : DbMigration { public override void Up() { this.CreateView("dbo.CasinosWithOver100SlotMachines", @"SELECT * FROM Casino.Casinos WHERE Id IN (SELECT CasinoId AS Id FROM Casino.SlotMachines GROUP BY CasinoId HAVING COUNT(CasinoId)>=100)"); }

    public override void Down() { this.RemoveView("dbo.CasinosWithOver100SlotMachines"); } }

    Figure 8 Using the New CreateView Operation

    Figure 9 The Newly Created View Generatedby Update-Database

    http://www.bit.ly/1dA0LZfhttp://www.bit.ly/1dA0LZfhttp://www.thedatafarm.com/bloghttp://www.twitter.com/julielermanhttp://www.twitter.com/julielermanhttp://www.thedatafarm.com/bloghttp://www.bit.ly/1dA0LZf
  • 5/27/2018 MDN_0114DG

    21/88

    http://www.leadtools.com/
  • 5/27/2018 MDN_0114DG

    22/88

    PRODUCED BYSUPPORTED BY

    magazine

    WITH

    MAYTHE

    CODEBE

    YOU!

    0011001001010010101001010

    101101001010101011010100101001010010101

    0010010101010101101010001001010101010010000100110011011100010101010

    1101010010000100001100101

    000100100011010100101011010000101101011

    010101110010000101000110011010101010011100110101000110101010001101110

    0010101000100101010011101

    011011001010101011010100101001000000110

    101010001001010010101011100100010101101010000100111000010111001001000

    0110010101010010010101010

    110010101000110101000101001010100110101

    0101001010100010010101000100100010101100110110000101010001101110010

    PLATINUM SPONSOR

    http://www.vslive.com/lasvegashttp://www.vslive.com/lasvegashttp://www.vslive.com/lasvegashttp://www.vslive.com/lasvegashttp://www.vslive.com/lasvegashttp://www.vslive.com/lasvegashttp://www.vslive.com/lasvegashttp://www.vslive.com/lasvegashttp://www.vslive.com/lasvegashttp://www.vslive.com/lasvegashttp://www.vslive.com/lasvegashttp://www.vslive.com/lasvegashttp://www.vslive.com/lasvegashttp://www.vslive.com/lasvegashttp://www.vslive.com/lasvegashttp://www.vslive.com/lasvegashttp://www.vslive.com/lasvegashttp://www.vslive.com/lasvegashttp://www.vslive.com/lasvegashttp://www.vslive.com/lasvegashttp://www.vslive.com/lasvegashttp://www.vslive.com/lasvegashttp://www.vslive.com/lasvegashttp://www.vslive.com/lasvegashttp://www.vslive.com/lasvegashttp://www.vslive.com/lasvegashttp://www.vslive.com/lasvegashttp://www.vslive.com/lasvegashttp://www.vslive.com/lasvegashttp://www.vslive.com/lasvegashttp://www.vslive.com/lasvegashttp://www.vslive.com/lasvegashttp://www.vslive.com/lasvegashttp://www.vslive.com/lasvegashttp://www.vslive.com/lasvegashttp://www.vslive.com/lasvegashttp://www.vslive.com/lasvegashttp://www.vslive.com/lasvegashttp://www.vslive.com/lasvegashttp://www.vslive.com/lasvegashttp://www.vslive.com/lasvegashttp://www.vslive.com/lasvegashttp://www.vslive.com/lasvegashttp://www.vslive.com/lasvegashttp://www.vslive.com/lasvegashttp://www.vslive.com/lasvegashttp://www.vslive.com/lasvegashttp://www.vslive.com/lasvegashttp://www.vslive.com/lasvegashttp://www.vslive.com/lasvegashttp://www.vslive.com/lasvegashttp://www.vslive.com/lasvegashttp://www.vslive.com/lasvegashttp://www.vslive.com/lasvegashttp://www.vslive.com/lasvegashttp://www.vslive.com/lasvegashttp://www.vslive.com/lasvegashttp://www.vslive.com/lasvegashttp://www.vslive.com/lasvegashttp://www.vslive.com/lasvegashttp://www.vslive.com/lasvegashttp://www.vslive.com/lasvegashttp://www.vslive.com/lasvegashttp://www.vslive.com/lasvegashttp://www.vslive.com/lasvegashttp://www.vslive.com/lasvegashttp://www.vslive.com/lasvegashttp://www.vslive.com/lasvegashttp://www.vslive.com/lasvegashttp://www.vslive.com/lasvegashttp://www.vslive.com/lasvegashttp://www.vslive.com/lasvegashttp://www.vslive.com/lasvegashttp://www.vslive.com/lasvegashttp://www.vslive.com/lasvegashttp://www.vslive.com/lasvegashttp://www.vslive.com/lasvegashttp://www.vslive.com/lasvegashttp://www.vslive.com/lasvegashttp://www.vslive.com/lasvegashttp://www.vslive.com/lasvegashttp://www.vslive.com/lasvegashttp://www.vslive.com/lasvegashttp://www.vslive.com/lasvegashttp://www.vslive.com/lasvegashttp://www.vslive.com/lasvegashttp://www.vslive.com/lasvegashttp://www.vslive.com/lasvegashttp://www.vslive.com/lasvegashttp://www.vslive.com/lasvegashttp://www.vslive.com/lasvegashttp://www.vslive.com/lasvegashttp://www.vslive.com/lasvegashttp://www.vslive.com/lasvegashttp://www.vslive.com/lasvegashttp://www.vslive.com/lasvegashttp://www.vslive.com/lasvegashttp://www.vslive.com/lasvegashttp://www.vslive.com/lasvegashttp://www.vslive.com/lasvegashttp://www.vslive.com/lasvegashttp://www.vslive.com/lasvegashttp://www.vslive.com/lasvegashttp://www.vslive.com/lasvegashttp://www.vslive.com/lasvegashttp://www.vslive.com/lasvegashttp://www.vslive.com/lasvegashttp://www.vslive.com/lasvegashttp://www.vslive.com/lasvegashttp://www.vslive.com/lasvegashttp://www.vslive.com/lasvegashttp://www.vslive.com/lasvegashttp://www.vslive.com/lasvegashttp://www.vslive.com/lasvegashttp://www.vslive.com/lasvegashttp://www.vslive.com/lasvegashttp://www.vslive.com/lasvegashttp://www.vslive.com/lasvegashttp://www.vslive.com/lasvegashttp://www.vslive.com/lasvegashttp://www.vslive.com/lasvegashttp://www.vslive.com/lasvegashttp://www.vslive.com/lasvegashttp://www.vslive.com/lasvegashttp://www.vslive.com/lasvegashttp://www.vslive.com/lasvegashttp://www.vslive.com/lasvegashttp://www.vslive.com/lasvegashttp://www.vslive.com/lasvegashttp://www.vslive.com/lasvegashttp://www.vslive.com/lasvegashttp://www.vslive.com/lasvegashttp://www.vslive.com/lasvegashttp://www.vslive.com/lasvegashttp://www.vslive.com/lasvegashttp://www.vslive.com/lasvegashttp://www.vslive.com/lasvegashttp://www.vslive.com/lasvegashttp://www.vslive.com/lasvegashttp://www.vslive.com/lasvegashttp://www.vslive.com/lasvegashttp://www.vslive.com/lasvegashttp://www.vslive.com/lasvegashttp://www.vslive.com/lasvegashttp://www.vslive.com/lasvegashttp://www.vslive.com/lasvegashttp://www.vslive.com/lasvegashttp://www.vslive.com/lasvegashttp://www.vslive.com/lasvegashttp://www.vslive.com/lasvegashttp://www.vslive.com/lasvegashttp://www.vslive.com/lasvegashttp://www.vslive.com/lasvegashttp://www.vslive.com/lasvegashttp://www.vslive.com/lasvegashttp://www.vslive.com/lasvegashttp://www.vslive.com/lasvegashttp://www.vslive.com/lasvegashttp://www.vslive.com/lasvegashttp://www.vslive.com/lasvegashttp://www.vslive.com/lasvegashttp://www.vslive.com/lasvegashttp://www.vslive.com/lasvegashttp://www.vslive.com/lasvegashttp://www.vslive.com/lasvegashttp://www.vslive.com/lasvegashttp://www.vslive.com/lasvegashttp://www.vslive.com/lasvegashttp://www.vslive.com/lasvegashttp://www.vslive.com/lasvegashttp://www.vslive.com/lasvegashttp://www.vslive.com/lasvegashttp://www.vslive.com/lasvegashttp://www.vslive.com/lasvegashttp://www.vslive.com/lasvegashttp://www.vslive.com/lasvegashttp://www.vslive.com/lasvegashttp://www.vslive.com/lasvegashttp://www.vslive.com/lasvegashttp://www.vslive.com/lasvegashttp://www.vslive.com/lasvegashttp://www.vslive.com/lasvegashttp://www.vslive.com/lasvegashttp://www.vslive.com/lasvegashttp://www.vslive.com/lasvegashttp://www.vslive.com/lasvegashttp://www.vslive.com/lasvegashttp://www.vslive.com/lasvegashttp://www.vslive.com/lasvegashttp://www.vslive.com/lasvegashttp://www.vslive.com/lasvegashttp://www.vslive.com/lasvegashttp://www.vslive.com/lasvegashttp://www.vslive.com/lasvegashttp://www.vslive.com/lasvegashttp://www.vslive.com/lasvegashttp://www.vslive.com/lasvegashttp://www.vslive.com/lasvegashttp://www.vslive.com/lasvegashttp://www.vslive.com/lasvegashttp://www.vslive.com/lasvegashttp://www.vslive.com/lasvegashttp://www.vslive.com/lasvegashttp://www.vslive.com/lasvegashttp://www.vslive.com/lasvegashttp://www.vslive.com/lasvegashttp://www.vslive.com/lasvegashttp://www.vslive.com/lasvegashttp://www.vslive.com/lasvegashttp://www.vslive.com/lasvegashttp://www.vslive.com/lasvegashttp://www.vslive.com/lasvegashttp://www.vslive.com/lasvegashttp://www.vslive.com/lasvegashttp://www.vslive.com/lasvegashttp://www.vslive.com/lasvegashttp://www.vslive.com/lasvegashttp://www.vslive.com/lasvegashttp://www.vslive.com/lasvegashttp://www.vslive.com/lasvegashttp://www.vslive.com/lasvegashttp://www.vslive.com/lasvegashttp://www.vslive.com/lasvegashttp://www.vslive.com/lasvegashttp://www.vslive.com/lasvegashttp://www.vslive.com/lasvegashttp://www.vslive.com/lasvegashttp://www.vslive.com/lasvegashttp://www.vslive.com/lasvegashttp://www.vslive.com/lasvegashttp://www.vslive.com/lasvegashttp://www.vslive.com/lasvegashttp://www.vslive.com/lasvegashttp://www.vslive.com/lasvegashttp://www.vslive.com/lasvegashttp://www.vslive.com/lasvegashttp://www.vslive.com/lasvegashttp://www.vslive.com/lasvegashttp://www.vslive.com/lasvegashttp://www.vslive.com/lasvegashttp://www.vslive.com/lasvegashttp://www.vslive.com/lasvegashttp://www.vslive.com/lasvegashttp://www.vslive.com/lasvegashttp://www.vslive.com/lasvegashttp://www.vslive.com/lasvegashttp://www.vslive.com/lasvegashttp://www.vslive.com/lasvegashttp://www.vslive.com/lasvegashttp://www.vslive.com/lasvegashttp://www.vslive.com/lasvegashttp://www.vslive.com/lasvegashttp://www.vslive.com/lasvegashttp://www.vslive.com/lasvegashttp://www.vslive.com/lasvegashttp://www.vslive.com/lasvegashttp://www.vslive.com/lasvegashttp://www.vslive.com/lasvegashttp://www.vslive.com/lasvegashttp://www.vslive.com/lasvegashttp://www.vslive.com/lasvegashttp://www.vslive.com/lasvegashttp://www.vslive.com/lasvegashttp://www.vslive.com/lasvegashttp://www.vslive.com/lasvegashttp://www.vslive.com/lasvegashttp://www.vslive.com/lasvegashttp://www.vslive.com/lasvegashttp://www.vslive.com/lasvegashttp://www.vslive.com/lasvegashttp://www.vslive.com/lasvegashttp://www.vslive.com/lasvegashttp://www.vslive.com/lasvegashttp://www.vslive.com/lasvegashttp://www.vslive.com/lasvegashttp://www.vslive.com/lasvegashttp://www.vslive.com/lasvegashttp://www.vslive.com/lasvegashttp://www.vslive.com/lasvegashttp://www.vslive.com/lasvegashttp://www.vslive.com/lasvegashttp://www.vslive.com/lasvegashttp://www.vslive.com/lasvegashttp://www.vslive.com/lasvegashttp://www.vslive.com/lasvegashttp://www.vslive.com/lasvegashttp://www.vslive.com/lasvegashttp://www.vslive.com/lasvegashttp://www.vslive.com/lasvegashttp://www.vslive.com/lasvegashttp://www.vslive.com/lasvegashttp://www.vslive.com/lasvegashttp://www.vslive.com/lasvegashttp://www.vslive.com/lasvegashttp://www.vslive.com/lasvegashttp://www.vslive.com/lasvegashttp://www.vslive.com/lasvegashttp://www.vslive.com/lasvegashttp://www.vslive.com/lasvegashttp://www.vslive.com/lasvegashttp://www.vslive.com/lasvegashttp://www.vslive.com/lasvegashttp://www.vslive.com/lasvegashttp://www.vslive.com/lasvegashttp://www.vslive.com/lasvegashttp://www.vslive.com/lasvegashttp://www.vslive.com/lasvegashttp://www.vslive.com/lasvegashttp://www.vslive.com/lasvegashttp://www.vslive.com/lasvegashttp://www.vslive.com/lasvegashttp://www.vslive.com/lasvegashttp://www.vslive.com/lasvegashttp://www.vslive.com/lasvegashttp://www.vslive.com/lasvegashttp://www.vslive.com/lasvegashttp://www.vslive.com/lasvegashttp://www.vslive.com/lasvegashttp://www.vslive.com/lasvegashttp://www.vslive.com/lasvegashttp://www.vslive.com/lasvegashttp://www.vslive.com/lasvegashttp://www.vslive.com/lasvegashttp://www.vslive.com/lasvegashttp://www.vslive.com/lasvegashttp://www.vslive.com/lasvegashttp://www.vslive.com/lasvegashttp://www.vslive.com/lasvegashttp://www.vslive.com/lasvegashttp://www.vslive.com/lasvegashttp://www.vslive.com/lasvegashttp://www.vslive.com/lasvegashttp://www.vslive.com/lasvegashttp://www.vslive.com/lasvegashttp://www.vslive.com/lasvegashttp://www.vslive.com/lasvegashttp://www.vslive.com/lasvegashttp://www.vslive.com/lasvegashttp://www.vslive.com/lasvegashttp://www.vslive.com/lasvegashttp://www.vslive.com/lasvegashttp://www.vslive.com/lasvegashttp://www.vslive.com/lasvegashttp://www.vslive.com/lasvegashttp://www.vslive.com/lasvegashttp://www.vslive.com/lasvegashttp://www.vslive.com/lasvegashttp://www.vslive.com/lasvegashttp://www.vslive.com/lasvegashttp://www.vslive.com/lasvegashttp://www.vslive.com/lasvegashttp://www.vslive.com/lasvegashttp://www.vslive.com/lasvegashttp://www.vslive.com/lasvegashttp://www.vslive.com/lasvegashttp://www.vslive.com/lasvegashttp://www.vslive.com/lasvegashttp://www.vslive.com/lasvegashttp://www.vslive.com/lasvegashttp://www.vslive.com/lasvegashttp://www.vslive.com/lasvegashttp://www.vslive.com/lasvegashttp://www.vslive.com/lasvegashttp://www.vslive.com/lasvegashttp://www.vslive.com/lasvegashttp://www.vslive.com/lasvegashttp://www.vslive.com/lasvegashttp://www.vslive.com/lasvegashttp://www.vslive.com/lasvegashttp://www.vslive.com/lasvegashttp://www.vslive.com/lasvegashttp://www.vslive.com/lasvegashttp://www.vslive.com/lasvegashttp://www.vslive.com/lasvegashttp://www.vslive.com/lasvegashttp://www.vslive.com/lasvegashttp://www.vslive.com/lasvegashttp://www.vslive.com/lasvegashttp://www.vslive.com/lasvegashttp://www.vslive.com/lasvegashttp://www.vslive.com/lasvegashttp://www.vslive.com/lasvegashttp://www.vslive.com/lasvegashttp://www.vslive.com/lasvegashttp://www.vslive.com/lasvegashttp://www.vslive.com/lasvegashttp://www.vslive.com/lasvegashttp://www.vslive.com/lasvegashttp://www.vslive.com/lasvegashttp://www.vslive.com/lasvegashttp://www.vslive.com/lasvegashttp://www.vslive.com/lasvegashttp://www.vslive.com/lasvegashttp://www.vslive.com/lasvegashttp://www.vslive.com/lasvegashttp://www.vslive.com/lasvegashttp://www.vslive.com/lasvegashttp://www.vslive.com/lasvegashttp://www.vslive.com/lasvegashttp://www.vslive.com/lasvegashttp://www.vslive.com/lasvegashttp://www.vslive.com/lasvegashttp://www.vslive.com/lasvegashttp://www.vslive.com/lasvegashttp://www.vslive.com/lasvegashttp://www.vslive.com/lasvegashttp://www.vslive.com/lasvegashttp://www.vslive.com/lasvegashttp://www.vslive.com/lasvegashttp://www.vslive.com/lasvegashttp://www.vslive.com/lasvegashttp://www.vslive.com/lasvegashttp://www.vslive.com/lasvegashttp://www.vslive.com/lasvegashttp://www.vslive.com/lasvegashttp://www.vslive.com/lasvegashttp://www.vslive.com/lasvegashttp://www.vslive.com/lasvegashttp://www.vslive.com/lasvegashttp://www.vslive.com/lasvegashttp://www.vslive.com/lasvegashttp://www.vslive.com/lasvegashttp://www.vslive.com/lasvegashttp://www.vslive.com/lasvegashttp://www.vslive.com/lasvegashttp://www.vslive.com/lasvegashttp://www.vslive.com/lasvegashttp://www.vslive.com/lasvegashttp://www.vslive.com/lasvegashttp://www.vslive.com/lasvegashttp://www.vslive.com/lasvegashttp://www.vslive.com/lasvegashttp://www.vslive.com/lasvegashttp://www.vslive.com/lasvegashttp://www.vslive.com/lasvegashttp://www.vslive.com/lasvegashttp://www.vslive.com/lasvegashttp://www.vslive.com/lasvegashttp://www.vslive.com/lasvegashttp://www.vslive.com/lasvegashttp://www.vslive.com/lasvegashttp://www.vslive.com/lasvegashttp://www.vslive.com/lasvegashttp://www.vslive.com/lasvegashttp://www.vslive.com/lasvegashttp://www.vslive.com/lasvegashttp://www.vslive.com/lasvegashttp://www.vslive.com/lasvegashttp://www.vslive.com/lasvegashttp://www.vslive.com/lasvegashttp://www.vslive.com/lasvegashttp://www.vslive.com/lasvegashttp://www.vslive.com/lasvegashttp://www.vslive.com/lasvegashttp://www.vslive.com/lasvegashttp://www.vslive.com/lasvegashttp://www.vslive.com/lasvegashttp://www.vslive.com/lasvegashttp://www.vslive.com/lasvegashttp://www.vslive.com/lasvegashttp://www.vslive.com/lasvegashttp://www.vslive.com/lasvegashttp://www.vslive.com/lasvegashttp://www.vslive.com/lasvegashttp://www.vslive.com/lasvegashttp://www.vslive.com/lasvegashttp://www.vslive.com/lasvegashttp://www.vslive.com/lasvegashttp://www.vslive.com/lasvegashttp://www.vslive.com/lasvegashttp://www.vslive.com/lasvegashttp://www.vslive.com/lasvegashttp://www.vslive.com/lasvegashttp://www.vslive.com/lasvegashttp://www.vslive.com/lasvegashttp://www.vslive.com/lasvegashttp://www.vslive.com/lasvegashttp://www.vslive.com/lasvegashttp://www.vslive.com/lasvegashttp://www.vslive.com/lasvegashttp://www.vslive.com/lasvegashttp://www.vslive.com/lasvegashttp://www.vslive.com/lasvegashttp://www.vslive.com/lasvegashttp://www.vslive.com/lasvegashttp://www.vslive.com/lasvegashttp://www.vslive.com/lasvegashttp://www.vslive.com/lasvegashttp://www.vslive.com/lasvegashttp://www.vslive.com/lasvegashttp://www.vslive.com/lasvegashttp://www.vslive.com/lasvegashttp://www.vslive.com/lasvegashttp://www.vslive.com/lasvegashttp://www.vslive.com/lasvegashttp://www.vslive.com/lasvegashttp://www.vslive.com/lasvegashttp://www.vslive.com/lasvegashttp://www.vslive.com/lasvegashttp://www.vslive.com/lasvegashttp://www.vslive.com/lasvegashttp://www.vslive.com/lasvegashttp://www.vslive.com/lasvegashttp://www.vslive.com/lasvegashttp://www.vslive.com/lasvegashttp://www.vslive.com/lasvegashttp://www.vslive.com/lasvegashttp://www.vslive.com/lasvegashttp://www.vslive.com/lasvegashttp://www.vslive.com/lasvegashttp://www.vslive.com/lasvegashttp://www.vslive.com/lasvegashttp://www.vslive.com/lasvegashttp://www.vslive.com/lasvegashttp://www.vslive.com/lasvegashttp://www.vslive.com/lasvegashttp://www.vslive.com/lasvegashttp://www.vslive.com/lasvegashttp://www.vslive.com/lasvegashttp://www.vslive.com/lasvegashttp://www.vslive.com/lasvegashttp://www.vslive.com/lasvegashttp://www.vslive.com/lasvegashttp://www.vslive.com/lasvegashttp://www.vslive.com/lasvegashttp://www.vslive.com/lasvegashttp://www.vslive.com/lasvegashttp://www.vslive.com/lasvegashttp://www.vslive.com/lasvegashttp://www.vslive.com/lasvegashttp://www.vslive.com/lasvegashttp://www.vslive.com/lasvegashttp://www.vslive.com/lasvegashttp://www.vslive.com/lasvegashttp://www.vslive.com/lasvegashttp://www.vslive.com/lasvegas
  • 5/27/2018 MDN_0114DG

    23/88

    LAS VEGAS 2O14March10-14|PlanetHollywoodHotel&Casino

    VisualStudioLive!is your guide

    to the .NET Development universe,featuring code-lled days,

    networking nights and independent

    education. Whether you are a .NET

    developer, software architect or a

    designer, Visual Studio Live!s

    multi-track events include focused,

    cutting-edge education on the .NET

    platform that youll be ready to

    implement as soon as you get backto the ofce.

    vslive.com/lasvegas

    TURN THE PAGE FOR MORE EVENT DETAILS

    VisualStudioLive!Las Vegas is part ofLive! 360 DEV, which means youll haveaccess to four (4) other co-located events

    atnoadditionalcost:

    Five(5)eventsmeans over a hundredsessions to choose from mix and matchsessions to create your own, custom eventline-up - its like no other dev conferenceavailable today!

    AND INTRODUCING Web Dev Live!

    Scan the QR code toregister or for moreevent details.

    RegisterbyJanuary22andSave$400!Use promo code VSLJAN4

    COMPREHENSIVETRAINING

    FORT

    HEDEVELOPERWORLD.

    vslive.com/lasvegas

    http://www.vslive.com/lasvegashttp://www.vslive.com/lasvegashttp://www.vslive.com/lasvegashttp://www.vslive.com/lasvegashttp://www.vslive.com/lasvegashttp://www.vslive.com/lasvegashttp://www.vslive.com/lasvegashttp://www.vslive.com/lasvegashttp://www.vslive.com/lasvegashttp://www.vslive.com/lasvegashttp://www.vslive.com/lasvegashttp://www.vslive.com/lasvegashttp://www.vslive.com/lasvegashttp://www.vslive.com/lasvegashttp://www.vslive.com/lasvegashttp://www.vslive.com/lasvegashttp://www.vslive.com/lasvegashttp://www.vslive.com/lasvegashttp://www.vslive.com/lasvegashttp://www.vslive.com/lasvegashttp://www.vslive.com/lasvegashttp://www.vslive.com/lasvegashttp://www.vslive.com/lasvegashttp://www.vslive.com/lasvegashttp://www.vslive.com/lasvegashttp://www.vslive.com/lasvegashttp://www.vslive.com/lasvegashttp://www.vslive.com/lasvegashttp://www.vslive.com/lasvegashttp://www.vslive.com/lasvegashttp://www.vslive.com/lasvegashttp://www.vslive.com/lasvegashttp://www.vslive.com/lasvegashttp://www.vslive.com/lasvegashttp://www.vslive.com/lasvegashttp://www.vslive.com/lasvegashttp://www.vslive.com/lasvegashttp://www.vslive.com/lasvegashttp://www.vslive.com/lasvegashttp://www.vslive.com/lasvegashttp://www.vslive.com/lasvegashttp://www.vslive.com/lasvegashttp://www.vslive.com/lasvegashttp://www.vslive.com/lasvegashttp://www.vslive.com/lasvegashttp://www.vslive.com/lasvegashttp://www.vslive.com/lasvegashttp://www.vslive.com/lasvegashttp://www.vslive.com/lasvegashttp://www.vslive.com/lasvegashttp://www.vslive.com/lasvegashttp://www.vslive.com/lasvegashttp://www.vslive.com/lasvegashttp://www.vslive.com/lasvegas
  • 5/27/2018 MDN_0114DG

    24/88

    VISUAL STUDIO LIVE! WEB DEV LIVE!

    START TIME END TIME Pre-Conference Workshops: Monday, March 10, 2014 (Separate entry fee required)

    7:30 AM 9:00 AM Pre-Conference Workshop Registration - Coffee and Morning Pastries

    9:00 AM 6:00 PMLWM01Workshop: Building Distributed Modern Apps in C#and XAML - Rockford Lhotka

    LWM02Workshop: Modern UX Design - Billy Hollis

    LWM03Workshop: Data-Centric SPage Applications with Knockout,

    Durandal, Breeze, and Web API- Brian Noyes

    7:00 PM 9:00 PM Dine-A-Round Dinner

    START TIME END TIME Day1:Tuesday,March11,2014

    7:00 AM 8:00 AM Registration - Coffee and Morning Pastries

    8 :00 AM 9:00 AM Keynote: To Be Announced

    9:15 AM 10:30 AMLT01Visual Studio 2013 New IDE FeaturesPart I - Deborah Kurata

    LT02Whats New for HTML/WinJSWindows Store Apps - Ben Dewey

    LT03Introduction to Azure- Vishwas Lele

    LT04HTML5 for Better Web Sites- Robert Boedigheimer

    10 :45 AM 12:00 PMLT08Visual Studio 2013 New IDEFeatures Part II - Deborah Kurata

    LT09Whats New for XAMLWindows Store Apps - Ben Dewey

    LT10Windows Azure Cloud Services- Vishwas Lele

    LT1112Things Every Developer RNeeds to Know About JavaScript- Rachel Appel

    12:00 PM 1:15 PM Lunch V isit the E XPO

    1:15 PM 2:15 PM LT15- Chalk Talk: To Be AnnouncedLT16Chalk Talk: Introduction to SpRecognition with C# -James McCa

    2:30 PM 3:45 PMLT19Whats New in Team FoundationServer 2013 - Benjamin Day

    LT20Controlling Hardware UsingWindows 8.1 - Brian Peek

    LT21WCF & Web API: Can We AllJust Get Along?!? - Miguel Castro

    LT22Great User Experiences withCSS 3 - Robert Boedigheimer

    3:45 PM 4:15 PM Networking Break Vis it the EXPO

    4:15 PM 5:30 PMLT26Visual Studio Online: Cloud-yVisual Studio & TFS for Your Teams- Benjamin Day

    LT27Performance and Diagnostics Hubin Visual Studio 2013 - Brian Peek

    LT28Windows Azure Web Sites- Vishwas Lele

    LT29Writing Next Generation Javwith TypeScript - Rachel Appel

    5:30 PM 7:00 PM Welcome Reception

    START TIME END TIME Day 2: Wednesday, March 12, 2014

    7:00 AM 8:00 AM Registration - Coffee and Morning Pastries

    8 :00 AM 9:00 AM Keynote: To Be Announced

    9:15 AM 10:30 AMLW01 Getting Started with WindowsPhone Development - Nick Landry

    LW02Test Your XAML-based WindowsStore Apps with VS2013 - Benjamin Day

    LW03Overview of IaaS in WindowsAzure with Virtual Machines- Eric D. Boyd

    LW04Using jQuery to Replace theAjax Control Toolkit - Robert Boed

    10 :45 AM 12:00 PMLW08Developing Windows Phone Appswith Azure - Rockford Lhotka

    LW09Accelerate Your App Designwith Blend for Visual Studio 2013

    - Brian Noyes

    LW10Building Real-time, Multi-userInteractive Web and MobileApplications Using SignalR- Marcel de Vries

    LW11Building Web Applications UKendo UI and the MVVM Pattern

    -Ben Hoelting

    12:00 PM 1:15 PM Birds-of-a-Feather Lunch Visit the EXPO

    1:15 PM 2:30 PM

    LW15Cross Platform Native MobileApp Development for iOS, Android andWindows Using the Power of C#- Marcel de Vries

    LW16Holy Updates! (Or Whats Newin Windows 8.1) - Philip Japikse

    LW17Persistence In The Cloud: Howto Use Azure Storage - David Giard

    LW18Angular for .NET Developer-Jesse Liberty

    2:45 PM 4:00 PMLW22Mobile App Development for theWeb Developer Using PhoneGap- Eric D. Boyd

    LW23WinRT Business ApplicationArchitecture - Rockford Lhotka

    LW24Building Services with ASP.NETMVC Web API Deep Dive-Marcel de Vries

    LW25Build Your First AngularWeb Application - Matthew DiFran

    4:00 PM 4:30 PM Sponsored Break Visi t the EXPO Expo Raf e @ 4:15PM

    4:30 PM 5:45 PMLW29iOS Development Survival Guidefor the .NET Guy - Nick Landry

    LW30Overview of the Bing Platform -Brian Peek

    LW31Debugging and MonitoringWindows Azure Cloud Services- Eric D. Boyd

    LW32 Connecting the Dots: UsingHTML5, jQuery, and Web API Toge- David Giard

    7:00 PM 9:0 0 PM Live! 360 Evening Event

    START TIME END TIME Day 3: Thursday, March 13, 2014

    7:00 AM 8:00 AM Registration - Coffee and Morning Pastries

    8:00 AM 9:15 AMLTH01Whats New in .NET 4.5.1-Jason Bock

    LTH02Interaction Design Principlesand Patterns -Billy Hollis

    LTH03To Be AnnouncedLTH04Knocking it Out of the Parkwith Knockout.JS - Miguel Castro

    9:30 AM 10:45 AMLTH08Building Shared Mobile Apps forWindows Store and Windows Phone- Nick Landry

    LTH09Applying UX Design in XAML- Billy Hollis

    LTH10Learning Entity Framework 6- Leonard Lobel

    LTH11Structuring Your Single PagApplication with Durandal - Brian

    11 :00 AM 12:15 PMLTH15Visual Studio OnlineIts MoreThan You Know - Brian Randell

    LTH16Creating Games for Windows 8with Unity - Brian Lagunas

    LTH17To Be AnnouncedLTH18Create an API For Your AppWith Service Stack -Jesse Liberty

    12:15 PM 1:30 PM Lunch

    1:30 PM 2:45 PMLTH22App Insights - App PerformanceMonitoring - Brian Randell

    LTH23 Building Composite XAMLApplications with Prism - Brian Lagunas

    LTH24Asynchronous Debuggingin .NET -Jason Bock

    LTH25Busy Developers Guide toNode.js - Ted Neward

    3:00 PM 4:15 PMLTH29App Insights - Global SystemMonitoring - Brian Randell

    LTH30Implementing MVVM(Model-View-View Model) for WPF- Philip Japikse

    LTH31Browser as Code Editor:A Tour of Monaco -Jason Bock

    LTH32Busy Developers Guide toEverything Not-JavaScript - Ted Ne

    START TIME END TIME POST-CONFERENCE WORKSHOPS: FRIDAY, MARCH 14, 2014 (SEPARATE ENTRY FEE REQUIRED)

    7:30 AM 8:00 AM Post-Conference Workshop Registration - Coffee and Morning Pastries

    8:00 AM 05:00 PMLWF01Workshop: Deep Dive into Visual Studio 2013, TFS,and Visual Studio Online - Brian Randell

    LWF02 Workshop: Build and Submit a Game to the WindowsApp Store - David Giard

    LWF03Workshop: Busy DevelopeGuide to AngularJS - Ted Neward

    VISUAL STUDIO LIVE! TRACKS WEB DEV LIVE! TRACKS

    ASP.NET HVisual Studio / .NET

    Framework Windows 8.1 / WinRT WPF / Silverlight Cloud Computing Windows PhoneCross-Platform

    Mobile Development

    Speakers and sessions subject to change

    http://www.vslive.com/lasvegas
  • 5/27/2018 MDN_0114DG

    25/88

    CONNECT WITHVISUAL STUDIO LIVE!

    twitter.com/vslive@VSLive

    facebook.comSearchVSLive

    linkedin.comJointheVisualStudioLivegroup!

    vslive.com/lasvegas

    VISUAL STUDIO LIVE!HAS PARTNERED WITH

    PLANET HOLLYWOODHOTEL & CASINO ON ASPECIAL REDUCED RATEOF $109/NIGHT.

    SHAREPOINT LIVE! / SQL SERVER LIVE! MODERN APPS LIVE!

    LWM04Workshop: Building Apps withSharePoint 2013 - Darrin Bishop

    LWM05Crash Course onTechnologies for Modern AppDevelopment - Nick Landry& Kevin Ford

    LT05One ASP.NET - Game Changers for2013- Jesse Liberty

    LT06To Be Announced LT07Intro to Modern Apps

    LT12What's New in MVC 5 - Miguel CastroLT13SQL Server 2012/2014 Columnstore Indexes- Kevin Goff LT14

    Modern Apps Architecture

    LT17Chalk Talk: Access Services inSharePoint 2013 - What is it? - Darrin Bishop LT18

    Chalk Talk: To Be Announced

    LT23Build Real Time Websites withSignalR - Rachel Appel

    LT24SQL Server on Azure VMs- Eric D. Boyd

    LT25 Managing a DistributedProject Team

    LT30Whats New in Web API 2- Miguel Castro

    LT31T-SQL for Application Developers- Attendees Choose - Kevin Goff LT32

    TFS/ALM

    LW05Going Native with KendoUI Mobile-Keith Burnell

    LW06How SharePoint Apps areGoing to Save Us! - Bill Ayers LW07

    Design - Billy Hollis

    LW12Building Cross-Platform Phone Apps& Sites with jQuery Mobile - Nick Landry

    LW13Developing Using the SharePoint 2013REST Services - Matthew DiFranco

    LW14Unit Testing -Jason Bock

    LW19Tips for Building Multi-Touch EnabledWeb Sites - Ben Hoelting

    LW20 Introduction to Ofce 365SharePoint Online Development- Matthew DiFranco

    LW21Data Access and SQL Server

    LW26Build Once Deploy Everywherewith Icenium from Telerik - Ben Hoelting

    LW27Set Your Code Free! SharePoint Apps forthe Mobile World - Bill Ayers

    LW28Application Serversand Windows Azure

    LW33Building OData Services withASP.NET Web API - Brian Noyes

    LW34Test-Driven SharePoint 2013App Development - Bill Ayers

    LW35User Experience Nutsand Bolts

    LTH05Slice Development Time with ASP.NET MVC, Visual Studio, and Razor- Philip Japikse

    LTH06To Be Announced LTH07Android/Xamarin

    LTH12OWIN and Katana: The New HTTPHost for .NET Web Applications- Brock Allen

    LTH13Excel, Power BI and You: An Analytic sSuperhub -Andrew Brust

    LTH14Windows 8/Windows Phonewith C# and XAML

    LTH19Creating Map Centric WebApplications with HTML5 and JavaScript- Ben Ramseth

    LTH20Big Data 101 with HDInsight-Andrew Brust

    LTH21Leveraging your Datathrough BI

    LTH26Internals of Security for WebApplications in Visual Studio 2013- Brock Allen

    LTH27Database Development with SQL ServerData Tools - Leonard Lobel

    LTH28iOS

    LTH33Identity Management in ASP.NET- Brock Allen

    LTH34Windows Azure SQL Database SQL Server in the Cloud - Leonard Lobel

    LTH35 HTML5 and JavaScript

    LWF04Workshop: SQL Server for Developers-Andrew Brust & Leonard Lobel

    LWF05Deep Dive into Modern AppDesign and Development

    Developing Apps andSolutions for SharePoint

    SQL Server for theDeveloper

    SHAREPOINT LIVE! & SQL SERVER LIVE! TRACKS MODERN APPS LIVE! TRACK

    Mobile Web JavaScript Modern Apps Live!

    LAS VEGAS 2O14March10-14|PlanetHollywoodHotel&Casino

    Scan the QR code toregister or for moreevent details.

    RegisterbyJanuary22andSave$400!Use promo code VSLJAN4

    http://www.vslive.com/lasvegashttp://www.vslive.com/lasvegashttps://twitter.com/VSLivehttps://www.facebook.com/VSLiveEventshttp://www.linkedin.com/groups?gid=1844781&trk=hb_side_ghttp://www.linkedin.com/groups?gid=1844781&trk=hb_side_ghttp://www.vslive.com/lasvegashttp://www.vslive.com/lasvegashttp://www.vslive.com/lasvegashttp://www.vslive.com/lasvegashttp://www.vslive.com/lasvegashttp://www.vslive.com/lasvegashttp://www.vslive.com/lasvegashttp://www.vslive.com/lasvegashttp://www.vslive.com/lasvegashttp://www.vslive.com/lasvegashttp://www.vslive.com/lasvegashttp://www.vslive.com/lasvegashttp://www.vslive.com/lasvegashttp://www.vslive.com/lasvegashttp://www.vslive.com/lasvegashttp://www.vslive.com/lasvegashttp://www.vslive.com/lasvegashttp://www.linkedin.com/groups?gid=1844781&trk=hb_side_ghttps://www.facebook.com/VSLiveEventshttps://twitter.com/VSLivehttp://www.vslive.com/lasvegashttp://www.vslive.com/lasvegashttp://www.vslive.com/lasvegas
  • 5/27/2018 MDN_0114DG

    26/88

    msdn magazine22

    Believe it or not,sometimes app developers write code thatdoesnt work. Or the code works but is terribly inefficient and

    hogs memor y. Worse yet, ineffi cient code results in a poor UX,driving users crazy and compelling them to uninstall the app andleave bad reviews.

    Im going to explore common performance and efficiencyproblems you might encounter while building Windows Store appswith JavaScript. In this article, I take a look at best practices forerror handling using the Windows Library for JavaScript (WinJS).In a future article, Ill discuss techniques for doing work without

    blocking the UI t hread, specically using Web Workers or the newWinJS.Utilities.Scheduler API in WinJS 2.0, as found in Windows .1.

    Ill also present the new predictable-object lifecycle model in WinJS2.0, focusing particularly on when and how to dispose of controls.

    For each subject area, I focus on three things: Errors or ineffi ciencies that might arise in a Windows Store

    app built using JavaScript. Diagnostic tools for nding those errors and ineffi ciencies. WinJS APIs, features and best practices that can ameliorate

    specic problems.I provide some purposefully buggy code but, rest assured, I

    indicate in the code that something is or isnt supposed to work.I use Visual Studio 2013, Windows .1 and WinJS 2.0 for these

    demonstrations. Many of the diagnostic tools I use are provided

    in Visual Studio 2013. If you havent downloaded the most-recentversions of the tools, you can get them from the Windows DevCenter (bit.ly/K8nkk1). New diagnostic tools are released throughVisual Studio updates, so be sure to check for updates periodically.

    I assume signicant familiarity with building Windows Store appsusing JavaScript. If youre relatively new to the platform, I suggestbeginning with the basic Hello World example(bit.ly/vVbVHC) or,for more of a challenge, the Hilo sample for JavaScript(bit.ly/SgI0AA).

    Setting up the ExampleFirst, I create a new project in Visual Studio 2013 using theNavigation App template, which provides a good starting point

    for a basic multipage app. I also add a NavBar control (bit.ly/14vfvih)to the default.html page at the root of the solution, replacing the

    W I N J S ON W I N DOW S 8 . 1

    Build More EfficientWindows Store AppsUsing JavaScript:

    Error HandlingEric Schmidt

    This article discusses:

    Creating the sample project in Visual Studio 2013 using the

    Navigation App template

    Application-, page- and navigation-level error handling

    Asynchronous JavaScript debugging

    Technologies discussed:

    Windows 8.1, Windows Library for JavaScript 2.0, Visual Studio 2013

    Code download will be posted when available. Please check the

    online version of the article.

    GET HELP BUILDING YOUR WINDOWS STORE APP!

    Receive the tools, help and support you need to develop your

    Windows Store apps.

    bit.ly/XLjOrx

    http://www.vslive.com/lasvegashttp://www.bit.ly/K8nkk1http://www.bit.ly/K8nkk1http://www.bit.ly/K8nkk1http://www.bit.ly/vVbVHChttp://www.bit.ly/vVbVHChttp://www.bit.ly/vVbVHChttp://www.bit.ly/SgI0AAhttp://www.bit.ly/SgI0AAhttp://www.bit.ly/SgI0AAhttp://www.bit.ly/14vfvihhttp://www.bit.ly/14vfvihhttp://www.bit.ly/14vfvihhttp://www.bit.ly/XLjOrxhttp://www.bit.ly/14vfvihhttp://www.bit.ly/SgI0AAhttp://www.bit.ly/vVbVHChttp://www.bit.ly/K8nkk1http://www.bit.ly/XLjOrx
  • 5/27/2018 MDN_0114DG

    27/88

    23January 2014msdnmagazine.com

    AppBar code the template provided. Because I want to demonstratemultiple concepts, diagnostic tools and programming techniques,Ill add a new page to the app or each demonstration. Tis makesit much easier or me to navigate between all the test cases.

    Te complete HML m