CodeFluent Entities Live Demo Script
Transcription
CodeFluent Entities Live Demo Script
CodeFluent Entities Live Demo Script November 16 2010 The present document explains the steps to follow for the Orlando Visual Studio Live event planned from November 12th to November 16th, 2010. The objective is to show to attendees the basics CodeFluent Entities concepts through a live demonstration. Each step will be fully explained and all the code should be written in front of the attendees in order to make the demo as clearer as possible. No “hidden” manipulation will be admitted. CodeFluent Entities Live Demo Script using the Graphical Modeler Id 1. Description Launch Visual Studio 2010 and make sure the SQL Server is started (ex: net start mssql$demo) Launch SQL Server Management Studio 2. Create a new CodeFluent Blank Model with the following name Demo.VSLive.Model Remove .Model from solution Name 3. Leave the default namespace to Demo.VSLive and click OK ADDING ENTITIES 4. Select the Default surface and create the Movie entity in the namespace Media. Add the following properties: <cf:property name="Id" key="true" typeName="int" /> <cf:property name="Title" /> <cf:property name="Length" typeName="int" /> <cf:property name="WebSiteUrl"> <cf:rule typeName="UrlValidate" validSchemes="http" /> </cf:property> <cf:property name="Synopsis" typeName="richstring" maxLength="4000" /> <cf:property name="Year" typeName="int" /> <cf:property name="FilmPhoto" typeName="image" /> <cf:property name="Actors" typeName="string" /> 5. Property Actors will be configured later as an ActorCollection type. Create the Actor entity in the namespace Media. Add the following properties: <cf:property name="Id" key="true" typeName="int" /> <cf:property name="Name" /> CodeFluent Entities Live Demonstration using the Graphical Modeler. <cf:property name="Movies" typeName="string" /> 6. 7. Create a N-M relation between Movie and Actor: an actor can play in several movies and a movie has several actors. Make the association graphically by selecting the Movie.Actors property, holding the SHIFT button, and dragging the mouse on the Actor.Movies property. Ctrl + Shift + S to save the solution. ADDING INSTANCES 8. Add the following instances on Movie entity: Text Version: Title : Avatar Length : 95 WebSiteUrl : http://www.imdb.com/title/tt0499549 Synopsis : A paraplegic marine dispatched to the moon Pandora on a unique mission becomes torn between following his orders and protecting the world he feels is his home. Year : 2009 FilmPhoto : Browse for picture Title : The Princess and the Frog Length : 108 WebSiteUrl : http://www.imdb.com/title/tt0780521 Synopsis : A fairy tale set in Jazz Age-era New Orleans and centered on a young girl named Princess Tiana and her fateful kiss with a frog prince who desperately wants to be human again. Year : 2009 FilmPhoto : Browse for picture Title : Up In the Air CodeFluent Entities Live Demonstration using the Graphical Modeler. Length : 108 WebSiteUrl : http://www.imdb.com/title/tt1193138 Synopsis : With a job that has him traveling around the country firing people, Ryan Bingham leads an empty life out of a suitcase, until his company does the unexpected: ground him. Year : 2010 FilmPhoto : Browse for picture XML Version: <cf:instance> <cf:instanceValue name="Id">1</cf:instanceValue> <cf:instanceValue name="Title">Avatar</cf:instanceValue> <cf:instanceValue name="Length">95</cf:instanceValue> <cf:instanceValue name="WebSiteUrl">http://www.imdb.com/title/tt0499549</cf:instanceValue> <cf:instanceValue name="Synopsis">A paraplegic marine dispatched to the moon Pandora on a unique mission becomes torn between following his orders and protecting the world he feels is his home.</cf:instanceValue> <cf:instanceValue name="Year">2009</cf:instanceValue> <cf:instanceValue name="FilmPhoto" typeName="image">C:\UsersMy\Omid\Word\SoftFluent\0 - SoftFluent\6 - Events\26 - VS Live Orlando\01 - Demonstration\01 - Artefacts\Images\Avatar.jpg</cf:instanceValue> </cf:instance> <cf:instance> <cf:instanceValue name="Id">2</cf:instanceValue> <cf:instanceValue name="Title">The Princess and the Frog</cf:instanceValue> <cf:instanceValue name="Length">108</cf:instanceValue> <cf:instanceValue name="WebSiteUrl">http://www.imdb.com/title/tt0780521</cf:instanceValue> <cf:instanceValue name="Synopsis">A fairy tale set in Jazz Age-era New Orleans and centered on a young girl named Princess Tiana and her fateful kiss with a frog prince who desperately wants to be human again.</cf:instanceValue> <cf:instanceValue name="Year">2009</cf:instanceValue> <cf:instanceValue name="FilmPhoto" typeName="image">C:\UsersMy\Omid\Word\SoftFluent\0 - SoftFluent\6 - Events\26 - VS Live Orlando\01 - Demonstration\01 - Artefacts\Images\PrincesseEtLaGrenouille.jpg</cf:instanceValue> </cf:instance> <cf:instance> <cf:instanceValue name="Id">3</cf:instanceValue> <cf:instanceValue name="Title">Up In the Air</cf:instanceValue> <cf:instanceValue name="WebSiteUrl">http://www.imdb.com/title/tt1193138</cf:instanceValue> <cf:instanceValue name="Synopsis">With a job that has him traveling around the country firing people, Ryan Bingham leads an empty life out of a suitcase, until his company does the unexpected: ground him.</cf:instanceValue> <cf:instanceValue name="Length">110</cf:instanceValue> <cf:instanceValue name="FilmPhoto" typeName="image">C:\UsersMy\Omid\Word\SoftFluent\0 - SoftFluent\6 - Events\26 - VS CodeFluent Entities Live Demonstration using the Graphical Modeler. Live Orlando\01 - Demonstration\01 - Artefacts\Images\InTheAir.jpg</cf:instanceValue> <cf:instanceValue name="Year">2009</cf:instanceValue> </cf:instance> 9. Add the following instances on Actor entity by doing a copy and paste directly in the part. Explain to attendees that we proceed this way to save time: <cf:instance> <cf:instanceValue <cf:instanceValue <cf:instanceValue </cf:instance> <cf:instance> <cf:instanceValue <cf:instanceValue <cf:instanceValue </cf:instance> <cf:instance> <cf:instanceValue <cf:instanceValue <cf:instanceValue </cf:instance> <cf:instance> <cf:instanceValue <cf:instanceValue <cf:instanceValue </cf:instance> <cf:instance> <cf:instanceValue <cf:instanceValue <cf:instanceValue </cf:instance> <cf:instance> <cf:instanceValue <cf:instanceValue <cf:instanceValue </cf:instance> <cf:instance> <cf:instanceValue name="Id">1</cf:instanceValue> name="Name">Sam Worthington</cf:instanceValue> name="Movies"><Id>1</Id></cf:instanceValue> name="Id">2</cf:instanceValue> name="Name">Zoe Saldana</cf:instanceValue> name="Movies"><Id>1</Id></cf:instanceValue> name="Id">3</cf:instanceValue> name="Name">Sigourney Weaver</cf:instanceValue> name="Movies"><Id>1</Id></cf:instanceValue> name="Id">4</cf:instanceValue> name="Name">China Moses</cf:instanceValue> name="Movies"><Id>2</Id></cf:instanceValue> name="Id">5</cf:instanceValue> name="Name">Anika Noni Rose</cf:instanceValue> name="Movies"><Id>2</Id></cf:instanceValue> name="Id">6</cf:instanceValue> name="Name">Liane Foly</cf:instanceValue> name="Movies"><Id>2</Id></cf:instanceValue> name="Id">7</cf:instanceValue> CodeFluent Entities Live Demonstration using the Graphical Modeler. <cf:instanceValue <cf:instanceValue </cf:instance> <cf:instance> <cf:instanceValue <cf:instanceValue <cf:instanceValue </cf:instance> <cf:instance> <cf:instanceValue <cf:instanceValue <cf:instanceValue </cf:instance> 10. name="Name">George Clooney</cf:instanceValue> name="Movies"><Id>3</Id></cf:instanceValue> name="Id">8</cf:instanceValue> name="Name">Anna Kendrick</cf:instanceValue> name="Movies"><Id>3</Id></cf:instanceValue> name="Id">9</cf:instanceValue> name="Name">Jason Bateman</cf:instanceValue> name="Movies"><Id>3</Id></cf:instanceValue> Ctrl + Shift + S to save the solution. ADDING VISUAL STUDIO PROJECTS FOR GENERATED FILES 11. 12. Add a new project Demo.VSLive.Persistence of type Database / SQL Server 2008 Database Project to the current solution. Configure the correct connectionString ! Explain that any kind of project can be used. Add a new project Demo.VSLive of type Visual C# / Class Library to the current solution. Remove the Class1.cs file. ADDING SQL and BOM PRODUCERS 13. 14. 15. Add the SQL Server producer and select the Demo.VSLive.Persistence project as the Target Directory. Add the BOM producer and select the Demo.VSLive project as the Target Directory. Ctrl + Shift + S to save the solution. LAUNCHING GENERATION 16. Display the Output window so attendees can see the generation in real time. Select Demo.VSLive.Model and click Build. 17. Quickly explain which files have been generated: SQL scripts and .cs files. 18. Show the generated database and explain that SQL scripts have been processed in real time. CodeFluent Entities Live Demonstration using the Graphical Modeler. 19. Compile the BOM ADDING ASP.NET WEBSITE 20. 21. 22. 23. 24. Add a new ASP.NET Web Application project to the solution. Name it Demo.VSLive.Website. Configure it as the StartUp Project. Add a reference to: BOM CodeFluent.Runtime.dll CodeFluent.Runtime.Web.dll In Site.Master file: Change the title to Welcome to VS Live Orlando! Add a new navigation link to ~/Movies.aspx with text Movies (just below “~/About.aspx”) Add the following code to web.config (remove the connectionStrings section): <configSections> <section name="Demo.VSLive" type="CodeFluent.Runtime.CodeFluentConfigurationSectionHandler, CodeFluent.Runtime" /> </configSections> <Demo.VSLive connectionString="database=Demo_VSLive;server=(local)\demo;Trusted_Connection=true" /> 25. 26. Change the authentication in web.config to None (existing is Forms) We need to declare the blob handler because we will manipulate BLOB from database (the photo of a film) Add the following code to web.config (in the system.web node): <httpHandlers> <add verb="GET, POST" path="blobhandler.ashx" type="Demo.VSLive.Web.HttpHandler, Demo.VSLive"/> </httpHandlers> 27. 28. Add a new page of type Web Forms using Master Page and name it Movies.aspx. As we will use some powerful custom controls provided by CodeFluent Entities, we need to register the CodeFluent.Runtime.Web assembly Add the following code to Movies.aspx at the top of the page (just below the <@ Page>): CodeFluent Entities Live Demonstration using the Graphical Modeler. <%@ Register TagPrefix="_cfr" Namespace="CodeFluent.Runtime.Web.UI.WebControls" Assembly="CodeFluent.Runtime.Web" %> 29. Add the following code to Movies.aspx (in the MainContent placeholder). Do it directly in Design Mode: Add the CommandField in the GridView Add the HyperLink Field directly in the HTML so it is faster to do Set DataKeyNames to “Id, RowVersion, WebSiteUrl” <asp:ObjectDataSource ID="MoviesDataSource" runat="server" DataObjectTypeName="Media.Movie" DeleteMethod="Delete" InsertMethod="Save" SelectMethod="LoadAll" TypeName="Media.MovieCollection" UpdateMethod="Save"> </asp:ObjectDataSource> <br /> <br /> Films list: <asp:GridView ID="MoviesGridView" runat="server" AutoGenerateColumns="False" CellPadding="4" DataKeyNames="Id,RowVersion" DataSourceID="MoviesDataSource"> <Columns> <asp:CommandField ShowDeleteButton="True" ShowEditButton="True" ShowSelectButton="True" /> <asp:BoundField DataField="Id" HeaderText="Id" ReadOnly="true"/> <asp:BoundField DataField="Title" HeaderText="Title" /> <asp:BoundField DataField="Length" HeaderText="Length" /> <asp:TemplateField HeaderText="WebSiteUrl"> <ItemTemplate> <asp:HyperLink ID="HyperLink1" runat="server" NavigateUrl='<%#Eval("WebSiteUrl") %>' Text="Visualize Online" /> </ItemTemplate> <EditItemTemplate> <asp:TextBox ID="TextBox1" runat="server" Text='<%#Bind("WebSiteUrl") %>' /> </EditItemTemplate> </asp:TemplateField> <asp:BoundField DataField="Synopsis" HeaderText="Synopsis" /> <asp:BoundField DataField="Year" HeaderText="Year" /> <asp:TemplateField HeaderText="Image"> <ItemTemplate> <_cfr:BinaryLargeObjectControl ID="FilmPhoto" runat="server" CodeFluent Entities Live Demonstration using the Graphical Modeler. UrlType="Image" value='<%#Eval("FilmPhoto") %>' NotFoundImageUrl=""> <ItemTemplate> <asp:Image runat="server" ID="img" ImageUrl='<%# Container.ImageUrl %>' AlternateText='<%#Container.FileName %>' Width='100' /> </ItemTemplate> </_cfr:BinaryLargeObjectControl> </ItemTemplate> </asp:TemplateField> </Columns> </asp:GridView> <br /> <br /> <asp:ObjectDataSource ID="ActorsDataSource" runat="server" DataObjectTypeName="Media.Actor" SelectMethod="PageLoadActorsMoviesByMovie" TypeName="Media.ActorCollection" StartRowIndexParameterName="pageIndex" MaximumRowsParameterName="pageSize"> <SelectParameters> <asp:Parameter DefaultValue="0" Name="pageIndex" Type="Int32" /> <asp:Parameter DefaultValue="10" Name="pageSize" Type="Int32" /> <_cfr:PageOptionsParameter Name="pageOptions" DefaultPageSize="100" /> <_cfr:SelectedParameter ControlID="MoviesGridView" Name="movie" /> </SelectParameters> </asp:ObjectDataSource> Actors list: <asp:GridView ID="ActorsGridView" runat="server" AutoGenerateColumns="False" CellPadding="4" DataKeyNames="Id,RowVersion" DataSourceID="ActorsDataSource" PageSize="2" AllowPaging="true"> <Columns> <asp:BoundField DataField="Id" HeaderText="Id"/> <asp:BoundField DataField="Name" HeaderText="Name" /> </Columns> </asp:GridView> 30. 31. Explain the code that has been added in the previous step. Click F5 to run the web site and show the result. CodeFluent Entities Live Demonstration using the Graphical Modeler. 32. Click on “Avatar” / Visualize Online to show how links are handled ADDING SORTING SUPPORT 33. 34. 35. 36. 37. 38. Select the Movie entity, press F4 to display the Properties window. Configure the following properties as sortable (set Is Sortable attribute to True): Title, Length, Year. Ctrl + Shift + S to save the solution. Generate to update the generated code Quickly show the code of the Movie_LoadAll stored procedure that handles sorting Configure sorting on the columns of the MoviesGridView by copying / pasting the following code ( between <Columns> and </Columns> ) <asp:CommandField ShowDeleteButton="True" ShowEditButton="True" ShowSelectButton="True" /> <asp:BoundField DataField="Id" HeaderText="Id" ReadOnly="true"/> <asp:BoundField DataField="Title" HeaderText="Title" SortExpression="[Movie].[Title]" /> <asp:BoundField DataField="Length" HeaderText="Length" SortExpression="[Movie].[Length]" /> <asp:TemplateField HeaderText="WebSiteUrl"> <ItemTemplate> <asp:HyperLink ID="HyperLink1" runat="server" NavigateUrl='<%#Eval("WebSiteUrl") %>' Text="Visualize Online" /> </ItemTemplate> <EditItemTemplate> <asp:TextBox ID="TextBox1" runat="server" Text='<%#Bind("WebSiteUrl") %>' /> </EditItemTemplate> </asp:TemplateField> <asp:BoundField DataField="Synopsis" HeaderText="Synopsis" /> <asp:BoundField DataField="Year" HeaderText="Year" SortExpression="[Movie].[Year]"/> <asp:TemplateField HeaderText="Image"> <ItemTemplate> <_cfr:BinaryLargeObjectControl ID="FilmPhoto" runat="server" ContextName="Demo.VSLive" UrlType="Image" value='<%#Eval("FilmPhoto") %>' NotFoundImageUrl=""> <ItemTemplate> <asp:Image runat="server" ID="img" ImageUrl='<%# Container.ImageUrl %>' AlternateText='<%#Container.FileName %>' Width='70' Height='100' /> </ItemTemplate> </_cfr:BinaryLargeObjectControl> </ItemTemplate> </asp:TemplateField> CodeFluent Entities Live Demonstration using the Graphical Modeler. 39. Add the following attribute on MoviesGridView : AllowSorting="true" OnSorting="OnSorting1" 40. Modify MoviesDataSource by copying /pasting the following code: <asp:ObjectDataSource ID="MoviesDataSource" runat="server" DataObjectTypeName="Media.Movie" DeleteMethod="Delete" InsertMethod="Save" SelectMethod="PageLoadAll" TypeName="Media.MovieCollection" UpdateMethod="Save" StartRowIndexParameterName="pageIndex" MaximumRowsParameterName="pageSize"> <SelectParameters> <asp:Parameter DefaultValue="0" Name="pageIndex" Type="Int32" /> <asp:Parameter DefaultValue="10" Name="pageSize" Type="Int32" /> <_cfr:PageOptionsParameter Name="pageOptions" DefaultPageSize="100" /> </SelectParameters> </asp:ObjectDataSource> 41. Add the following code for handling the OnSorting1 event: <script runat="server"> private void OnSorting1(object sender, GridViewSortEventArgs e) { PageOptionsParameter p = (PageOptionsParameter)MoviesDataSource.SelectParameters["pageOptions"]; p.HandlePostBackEvent(e); } </script> 42. 43. Ctrl + Shift + S to save the solution. Click F5 and show the result. ADDING LOCALIZATION PATTERN 44. Explain what is a Pattern CodeFluent Entities Live Demonstration using the Graphical Modeler. 45. 46. 47. 48. 49. 50. Explain the concept of Dynamic Modeling Explain that CodeFluent Entities contains by default the Localization and Text Search Patterns Add the localization pattern (right click on the Default surface, then Add/Pattern). Browse to the Patterns folder and select SoftFluent.Locazation.xml. Click Ok. Select Synopsis property of entity Movie and click F4. Click on the Patterns Properties menu, and set Is Localizable to True. Localize also the Title and WebSiteUrl properties. As the Localization pattern relies on SQL views, we must activate views generation in the SQL Producer Configure the SQL Server producer for generating views: set the Produce Views to True. 51. 52. 53. Launch a new generation Show the new MovieLocalized table and the generated Views (vActor, vMovie and vMovieLocalized) Add the following code in web.config: <globalization culture="auto" uiCulture="auto"/> 54. Add the following translation to existing Movie instances: For Avatar movie: - US o Title : Avatar o Synopsis : A paraplegic marine dispatched to the moon Pandora on a unique mission becomes torn between following his orders and protecting the world he feels is his home. o WebSiteUrl : http://www.imdb.com/title/tt0499549 - FR o Title : Avatar (FR) o Synopsis : Malgré sa paralysie, Jake Sully, un ancien marine immobilisé dans un fauteuil roulant, est resté un combattant au plus profond de son être. Il est recruté pour se rendre à des années-lumière de la Terre, sur Pandora, où de puissants groupes industriels exploitent un minerai rarissime destiné à résoudre la crise énergétique sur Terre. Parce que l'atmosphère de Pandora est toxique pour les humains, ceux-ci ont créé le Programme Avatar, qui permet à des " pilotes " humains de lier leur esprit à un avatar, un corps biologique commandé à distance, capable de survivre dans cette atmosphère létale. Ces avatars sont des CodeFluent Entities Live Demonstration using the Graphical Modeler. o hybrides créés génétiquement en croisant l'ADN humain avec celui des Na'vi, les autochtones de Pandora. WebSiteUrl : http://www.allocine.fr/film/fichefilm_gen_cfilm=61282.html For Princess and the Frog movie: - US o Title : The Princess and the Frog o Synopsis : A fairy tale set in Jazz Age-era New Orleans and centered on a young girl named Princess Tiana and her fateful kiss with a frog prince who desperately wants to be human again. o WebSiteUrl : http://www.imdb.com/title/tt0780521/ - FR o Title : La Princesse et la Grenouille o Synopsis : Un conte qui se déroule à la Nouvelle-Orléans, dans le légendaire quartier français, où vit une jeune fille nommée Tiana. o WebSiteUrl : http://www.allocine.fr/film/fichefilm_gen_cfilm=129003.html For Up In the Air movie: - US o Title : Up In the Air o Synopsis : With a job that has him traveling around the country firing people, Ryan Bingham leads an empty life out of a suitcase, until his company does the unexpected: ground him. o WebSiteUrl : http://www.imdb.com/title/tt1193138 - FR o Title : In The Air o Synopsis : L'odyssée de Ryan Bingham, un spécialiste du licenciement à qui les entreprises font appel pour ne pas avoir à se salir les mains. Dans sa vie privée, celui-ci fuit tout engagement (mariage, propriété, famille) jusqu'à ce que sa rencontre avec deux femmes ne le ramène sur terre. o WebSiteUrl : http://www.allocine.fr/film/fichefilm_gen_cfilm=138895.html Backup: this is the XML version in case localized instances must be added directly in the model: <_loc:Title cultureName="en-US">Avatar</_loc:Title> <_loc:Synopsis cultureName="en-US"> A paraplegic marine dispatched to the moon Pandora on a unique mission becomes torn between following his orders and protecting the world he feels is his home. </_loc:Synopsis> <_loc:WebSiteUrl cultureName="en-US"> </_loc:WebSiteUrl> CodeFluent Entities Live Demonstration using the Graphical Modeler. <_loc:Title cultureName="fr-FR">Avatar</_loc:Title> <_loc:Synopsis cultureName="fr-FR"> Malgré sa paralysie, Jake Sully, un ancien marine immobilisé dans un fauteuil roulant, est resté un combattant au plus profond de son être. Il est recruté pour se rendre à des années-lumière de la Terre, sur Pandora, où de puissants groupes industriels exploitent un minerai rarissime destiné à résoudre la crise énergétique sur Terre. Parce que l'atmosphère de Pandora est toxique pour les humains, ceux-ci ont créé le Programme Avatar, qui permet à des " pilotes " humains de lier leur esprit à un avatar, un corps biologique commandé à distance, capable de survivre dans cette atmosphère létale. Ces avatars sont des hybrides créés génétiquement en croisant l'ADN humain avec celui des Na'vi, les autochtones de Pandora. </_loc:Synopsis> <_loc:WebSiteUrl cultureName="fr-FR">http://www.allocine.fr/film/fichefilm_gen_cfilm=61282.html</_loc:WebSiteUrl> For Princess and the Frog movie : <_loc:Title cultureName="en-US">The Princess and the Frog</_loc:Title> <_loc:Synopsis cultureName="en-US"> A fairy tale set in Jazz Age-era New Orleans and centered on a young girl named Princess Tiana and her fateful kiss with a frog prince who desperately wants to be human again. </_loc:Synopsis> <_loc:WebSiteUrl cultureName="en-US">http://www.imdb.com/title/tt0780521</_loc:WebSiteUrl> <_loc:Title cultureName="fr-FR">La Princesse et la Grenouille</_loc:Title> <_loc:Synopsis cultureName="fr-FR"> Un conte qui se déroule à la Nouvelle-Orléans, dans le légendaire quartier français, où vit une jeune fille nommée Tiana. </_loc:Synopsis> <_loc:WebSiteUrl cultureName="fr-FR">http://www.allocine.fr/film/fichefilm_gen_cfilm=129003.html</_loc:WebSiteUrl> For Up In the Air movie : <_loc:Title cultureName="en-US">Up in the Air</_loc:Title> <_loc:Synopsis cultureName="en-US"> With a job that has him traveling around the country firing people, Ryan Bingham leads an empty life out of a suitcase, until his company does the unexpected: ground him. </_loc:Synopsis> <_loc:WebSiteUrl cultureName="en-US">http://www.imdb.com/title/tt1193138</_loc:WebSiteUrl> <_loc:Title cultureName="fr-FR">In the Air</_loc:Title> <_loc:Synopsis cultureName="fr-FR"> CodeFluent Entities Live Demonstration using the Graphical Modeler. L'odyssée de Ryan Bingham, un spécialiste du licenciement à qui les entreprises font appel pour ne pas avoir à se salir les mains. Dans sa vie privée, celui-ci fuit tout engagement (mariage, propriété, famille) jusqu'à ce que sa rencontre avec deux femmes ne le ramène sur terre. </_loc:Synopsis> <_loc:WebSiteUrl cultureName="fr-FR">http://www.allocine.fr/film/fichefilm_gen_cfilm=138895.html</_loc:WebSiteUrl> 55. Press F5 and show Movies.aspx page. ADDING MEMBERSHIP 56. 57. 58. Add membership support by right clicking on the Default surface, then select Context Tasks / Manage Membership Entities. Click on Properties next to User and click on Auto Create All. Click on Properties next to Role and click on Auto Create All. Create these 2 entities in a new namespace called Security. Click OK. Change the typeName of Id property of entities User and Role to int. Add a new instance on Role entity through the modeler. Add <Roles><Id>1</Id></Roles> for user joe directly in the XML because it is not supported in the current version of the modeler: <cf:instance> <cf:instanceValue name="Id">1</cf:instanceValue> <cf:instanceValue name="Name">Authenticated</cf:instanceValue> </cf:instance> 59. Add 2 instances on User entity. User joe belongs to group Authenticated but not peter: <cf:instance> <cf:instanceValue <cf:instanceValue <cf:instanceValue <cf:instanceValue <cf:instanceValue <cf:instanceValue <Roles> name="Id">1</cf:instanceValue> name="UserName">joe</cf:instanceValue> name="Email">[email protected]</cf:instanceValue> name="IsAnonymous">false</cf:instanceValue> name="Password">joe</cf:instanceValue> name="IsApproved">true</cf:instanceValue> CodeFluent Entities Live Demonstration using the Graphical Modeler. <Id>1</Id> </Roles> </cf:instance> <cf:instance> <cf:instanceValue <cf:instanceValue <cf:instanceValue <cf:instanceValue <cf:instanceValue <cf:instanceValue </cf:instance> 60. 61. 62. name="Id">2</cf:instanceValue> name="UserName">peter</cf:instanceValue> name="Email">[email protected]</cf:instanceValue> name="IsAnonymous">false</cf:instanceValue> name="IsApproved">true</cf:instanceValue> name="Password">peter</cf:instanceValue> Ctrl + Shift + S to save the solution Generate the new model. Add the support for membership and role in the web site. Add to web.config file, the following sections by replacing the existing ones: <membership defaultProvider="Demo.VSLive"> <providers> <clear /> <add name="Demo.VSLive" type="Demo.VSLive.Web.Security.MembershipProvider, Demo.VSLive" passwordFormat="Clear" /> </providers> </membership> <roleManager enabled="true" defaultProvider="Demo.VSLive"> <providers> <clear /> <add name="Demo.VSLive" type="Demo.VSLive.Web.Security.RoleProvider, Demo.VSLive" /> </providers> </roleManager> 63. 64. Change the authentication mode to Forms in web.config file. Secure the access to Movies.aspx page only to users belonging to Authenticated role by adding the following <location> node : <location path="Movies.aspx"> <system.web> <authorization> CodeFluent Entities Live Demonstration using the Graphical Modeler. <allow roles="Authenticated" /> <deny users="*" /> </authorization> </system.web> </location> 65. Press F5 and show the result by accessing the Movies.aspx page. Log on using peter account with password peter then with joe account with password joe who belongs to the Authenticated role. END OF DOCUMENT CodeFluent Entities Live Demonstration using the Graphical Modeler.