archive-gr.com » GR » D » DOTNETZONE.GR

Total: 987

Choose link from "Titles, links and description words view":

Or switch to "Titles and links view".
  • Dot Net Rules : Introduction to SQL Server Extended Events in SQL Server 2012
    short introduction and a demo on SQL Server Extented events In this post I will explain what Extended Events are and provide a hands on demo SQL Server Profiler is was the main tool for DBA admins and developers to find out why there were performance issues with SQL Server queries and troubleshoot them DBAs also use sql traces DBCC commands and trace flags for performance related issues Now we have an additional tool in our disposal We have SQL Server Extended events which were firstly introduced in SQL Server 2008 SQL Server 2008 introduced Extended Events which is a system for collecting event driven data about a SQL Server instance and its databases In SQL Server 2008 we had no GUI wizards for the extended events In that version of SQL Server 2008 we had to write complex T SQL statements to gather the information we needed to analyse The results from those SQL queries was returned in an XML format and sometimes it was difficult to analyse them In SQL Server 2012 we have support for Extended events in SQL Server Management Studio through a GUI component which makes working with Extended Events a simple operation You can find the Extended Events node under the Management folder in SSMS We use sessions we create and configure sessions to collect data in order to analyse it Extended events have less impact on the server resources than SQL Server Profiler Let s move on to our actual demo I will use Extended Εvents sessions to capture and analyse data about deadlocks We have a deadlock when two separate processes transactions hold locks on resources that each other needs Nothing can happen This situation could go on forever But one of the transactions is forced by SQL Server to die SQL Server selects a victim and kills the process transaction It usually kills the one that is least expensive to roll back We can also have some control over the process to be chosen to be the victim by setting the deadlock priority by typing SET DEADLOCK PRIORITY LOW This option makes SQL Server to choose that session to be the victim when a deadlock occurs If you want to find our more about deadlocks then have a look at this post of mine In that post I use the SQL Server Profiler to look for Deadlock events Deadlock Graph event I have installed in my Windows 8 machine an instance of SQL Server 2012 Enterprise edition You can download a trial version here You can install the developer edition of SQL Sever 2012 as well I connect to my local default instance of SQL Server 2012 through windows authentication Then I navigate to Management Extended Events Sessions New Session Wizard right click Have a look at the picture below Then we click Next In the next screen we need to give a name to our session Have a look at the picture below We give a name to our session

    Original URL path: http://www.dotnetzone.gr/cs/blogs/dotnetrules/archive/2013/11/12/introduction-to-sql-server-extended-events-in-sql-server-2012.aspx (2015-07-15)
    Open archived version from archive


  • Dot Net Rules : SQL Server 2012 Editions, License options and hardware limits
    2010 1 Οκτώβριος 2009 2 Σεπτέμβριος 2009 4 Ιούνιος 2009 5 Απρίλιος 2009 1 Μάρτιος 2009 3 Φεβρουάριος 2009 2 Δεκέμβριος 2008 3 Νοέμβριος 2008 10 Σεπτέμβριος 2008 1 Αύγουστος 2008 1 Ιούλιος 2008 9 Ιούνιος 2008 10 SQL Server 2012 Editions License options and hardware limits In a recent seminar I gave regarding SQL Server 2012 I was asked to clear a few things regarding SQL Server 2012 editions and their license options pricing In this post i will shed some light on this issue I will start by talking about the various license costs per SQL Server 2012 editions Please note that there is no datacenter and workgroup edition in SQL Server 2012 version Before I go on I would like you to note that there is not a socket licensing anymore A physical socket is what sits on the motherboard This is where the processor fits Multi core is a physical processor that has many cores in it For example you can have one socket with one processor that has four cores Some people are confused with the term logical core The new licensing model that is based on physical cores not logical ones Logical cores is a term that refers to hyper threading meaning we can have logical cores from each physical core In SQL Server 2012 Enterprise Edition we have a core based licensing system The cost is 6874 00 per core The absolute minimum is four core per socket In SQL Server 2012 Business Intelligence Edition the licensing system is different You have to pay a Server license plus CALs This is 8592 00 per server plus CALs which is 209 per CAL In SQL Server 2012 Standard Edition you can pick the licensing model that fits your needs You can go for c ore based which is 1793 00 per core The absolute minimum is four core per socket Alternatively you can go with S erver license plus CALs The cost is 898 00 per server plus CALs which is 209 00 per CAL These are the official figures If you have a virtualised environment you must license the virtual core in each virtual machine There is a minimum of 4 core lisenses required for each virtual machine Your organisation can have different arrangements with Microsoft In any case you can always have a look at the Microsoft License Advisor tool Now I would like to talk about the various editions and their hardware related license limits that could affect your hardware selection decisions e g the processor selection and how many cores it has In SQL Server 2012 Enterprise Edition we have features like database snapshots data compression table partitioning resource governor These are critical features for large databases and we must opt for that edition Naturally it has the highest license costs When it comes to operating system memory that can be used from SQL Server Enterprise Edition 2012 is all that the operating system can provide e g in Windows

    Original URL path: http://www.dotnetzone.gr/cs/blogs/dotnetrules/archive/2013/11/10/sql-server-2012-editions-license-options-and-hardware-limits.aspx (2015-07-15)
    Open archived version from archive

  • Dot Net Rules : Restoring the master database in SQL Server
    2013 14 Οκτώβριος 2013 2 Σεπτέμβριος 2013 5 Ιούλιος 2013 1 Ιανουάριος 2013 8 Δεκέμβριος 2012 11 Νοέμβριος 2012 3 Οκτώβριος 2012 12 Σεπτέμβριος 2012 16 Αύγουστος 2012 6 Ιούλιος 2012 13 Ιούνιος 2012 3 Μάιος 2012 4 Απρίλιος 2012 15 Μάρτιος 2012 8 Ιανουάριος 2012 3 Δεκέμβριος 2011 7 Νοέμβριος 2011 13 Οκτώβριος 2011 6 Σεπτέμβριος 2011 8 Αύγουστος 2011 6 Ιούλιος 2011 2 Μάιος 2011 1 Μάρτιος 2011 9 Φεβρουάριος 2011 15 Ιανουάριος 2011 14 Δεκέμβριος 2010 9 Νοέμβριος 2010 2 Οκτώβριος 2010 11 Σεπτέμβριος 2010 1 Αύγουστος 2010 3 Απρίλιος 2010 2 Μάρτιος 2010 5 Ιανουάριος 2010 1 Οκτώβριος 2009 2 Σεπτέμβριος 2009 4 Ιούνιος 2009 5 Απρίλιος 2009 1 Μάρτιος 2009 3 Φεβρουάριος 2009 2 Δεκέμβριος 2008 3 Νοέμβριος 2008 10 Σεπτέμβριος 2008 1 Αύγουστος 2008 1 Ιούλιος 2008 9 Ιούνιος 2008 10 Restoring the master database in SQL Server I had a seminar in SQL Server 2012 recently and one of the people in my class asked me what is the best way to restore a In this post I will like to shed some light on the issue As we all know we must include in our backup strategy the system databases backup We must backup the master and msdb databases regularly If for some reason the master database becomes corrupt or missing the SQL Server instance cannot be started Master and tempdb cannot be repaired Repair requires single user mode since master and tempdb cannot be put into single user mode If your SQL Server master database becomes corrupt some people suggest to rebuild the master database then start SQL Server then restore the backup of the master database I do not suggest rebuilding the master database That is really time consuming and you need to do a lot of trial and error

    Original URL path: http://www.dotnetzone.gr/cs/blogs/dotnetrules/archive/2013/11/10/restoring-the-master-database-in-sql-server.aspx (2015-07-15)
    Open archived version from archive

  • Dot Net Rules : Localizing an ASP.Net MVC 4.0 application
    13 Ιούνιος 2012 3 Μάιος 2012 4 Απρίλιος 2012 15 Μάρτιος 2012 8 Ιανουάριος 2012 3 Δεκέμβριος 2011 7 Νοέμβριος 2011 13 Οκτώβριος 2011 6 Σεπτέμβριος 2011 8 Αύγουστος 2011 6 Ιούλιος 2011 2 Μάιος 2011 1 Μάρτιος 2011 9 Φεβρουάριος 2011 15 Ιανουάριος 2011 14 Δεκέμβριος 2010 9 Νοέμβριος 2010 2 Οκτώβριος 2010 11 Σεπτέμβριος 2010 1 Αύγουστος 2010 3 Απρίλιος 2010 2 Μάρτιος 2010 5 Ιανουάριος 2010 1 Οκτώβριος 2009 2 Σεπτέμβριος 2009 4 Ιούνιος 2009 5 Απρίλιος 2009 1 Μάρτιος 2009 3 Φεβρουάριος 2009 2 Δεκέμβριος 2008 3 Νοέμβριος 2008 10 Σεπτέμβριος 2008 1 Αύγουστος 2008 1 Ιούλιος 2008 9 Ιούνιος 2008 10 Localizing an ASP Net MVC 4 0 application In this post I will demonstrate with a hands on demo how to localise your ASP Net MVC applications The most important thing to point out is that in this world we live in we should expect our site to be visited by various people from different cultures and languages So we must be prepared to have our site internationalised Thankfully ASP Net MVC simplifies the whole internationalisation localisation process I would like to talk about the Thread CurrentCulture property that impacts formatting That means that this property instructs the runtime how it should display strings e g the currency in or or how the date should be displayed The other imporant property is Thread CurrentUICulture which is used by the Resource Manager to look up culture specific resources at run time I have installed VS 2012 Ultimate edition in my Windows 8 machine Υou can use Visual Studio Express 2012 for Web You can install Visual Studio Express 2012 for Web if you download Web Platform Installer You can download this tool from this link 1 I am launching VS 2012 and I will Visual C as the programming language I will also select ASP NET MVC 4 Web Application from the available templates Choose C as the development language and Internet Application I will name my application MvcLocalization All the necessary files are created 2 In the Ιndex chstml view in the Home folder add the following code var mysalary 2450 0m var birthday new DateTime 1980 2 17 div mysalary ToString c div br div birthday ToShortDateString div I just declare two variables and output them back to the screen I format the mysalary value as currency 3 Now we need to change our settings in the web config file In the system web section add globalization culture auto uiCulture auto 4 Build and run your application and you should will see something like the picture below My default culture in this machine is US English So everything is formatted accordingly I go to Internet Explorer I view my app in IE Tools Languages Set Language Preferences and add another language Greek Now I run again my application Now I see the new culture format is applied in both my strings Have a look at the picture below The way ASP Net runtime

    Original URL path: http://www.dotnetzone.gr/cs/blogs/dotnetrules/archive/2013/10/04/localizing-an-asp-net-mvc-4-0-application.aspx (2015-07-15)
    Open archived version from archive

  • Dot Net Rules : Using the Repository Pattern in an ASP.Net MVC 4.0 application
    to create a context class that inherits from DbContext Add a new class to project Name it The FootballerDBContext Now that we have the entity class created we must let the model know I will have to use the DbSet T property The code for this class follows public class TheFootballerDBContext DbContext public DbSet Footballer Footballers get set Do not forget to add using System Data Entity in the beginning of the class file 4 We must take care of the connection string It is very easy to create one in the web config It does not matter that we do not have a database yet When we run the DbContext and query against it it will use a connection string in the web config and will create the database based on the classes I will use the LocalDb In my case the connection string inside the web config looks like this add name TheFootballerDBContext connectionString Data Source LocalDb v11 0 AttachDbFilename DataDirectory NewDBFootballers mdf Integrated Security True providerName System Data SqlClient 5 Now we need to access our model from a controller This is going to be a simple class that retrieves the footballers data I will add a reference to the MvcRepository DomainClasses project Right click the Controllers folder and create a new FootballerController controller Have a look at the picture below to set the appropriate settings and then click Add Have a look at the picture below Visual Studio 2012 will create the following A FootballerController cs file in the project s Controllers folder A Footballer folder in the project s Views folder Create cshtml Delete cshtml Details cshtml Edit cshtml and Index cshtml in the new Views Footballer folder Then we need to make a small change to the Layout cshtml file We will add this line of code to add another item in the menu so we can navigate to the Footballers page li Html ActionLink Footballers Index Footballer li 6 Build and run your application Navigate to the localhost youport footballer You have a UI ready for you to add edit delete footballers I will add 2 3 entries 7 Now we are ready to change our code to incorporate the Repository pattern I am going to show you the contents of the FootballerController cs class so you can see changes we will make to the controller later on when we incorporate the Repository pattern public class FootballerController Controller private TheFootballerDBContext db new TheFootballerDBContext GET Footballer public ActionResult Index return View db Footballers ToList GET Footballer Details 5 public ActionResult Details int id 0 Footballer footballer db Footballers Find id if footballer null return HttpNotFound return View footballer GET Footballer Create public ActionResult Create return View POST Footballer Create HttpPost ValidateAntiForgeryToken public ActionResult Create Footballer footballer if ModelState IsValid db Footballers Add footballer db SaveChanges return RedirectToAction Index return View footballer GET Footballer Edit 5 public ActionResult Edit int id 0 Footballer footballer db Footballers Find id if footballer null return HttpNotFound return View

    Original URL path: http://www.dotnetzone.gr/cs/blogs/dotnetrules/archive/2013/10/02/using-the-repository-pattern-in-an-asp-net-mvc-4-0-application.aspx (2015-07-15)
    Open archived version from archive

  • Dot Net Rules
    and ASP Net MVC to implement functionality commonly found on ASP Net web sites I have also used DotNetNuke DNN the Open Source Web Application Framework of my choice to build websites I am also the co admin of the greek DotNetNuke community and I decided that I will use this space to write a series of posts regarding DotNetNuke I have decided to keep those posts short I will provide tips and tricks and answers to questions I often get when I teach about DotNetNuke in open seminars I would like to introduce DotNetNuke to you before I move on DotNetNuke is an Open Source Web Application Framework that is based on ASP Net It is ideal for creating and deploying projects such as Commercial Web Sites Corporate Intranets and Extranets Online Publishing Portals Other Web Applications There are 3 DNN editions DotNetNuke Professional edition DotNetNuke Enterprise edition and DotNetNuke Community edition Have a look at a comparison of the various editions here I will be using the community edition in all my posts In this short post I will show you how to remove the DotNetNuke copyright message from the View source View Page Source of your DNN site Before I move on I must have a working installation of DNN I have installed DNN 7 0 in a web server You can see the default installation and site http dnn7 nopservices com In another post of mine I will demonstrate how to install DotNetNuke 7 0 in your machine or a live web server Let s move on with our actual example When I view my website http dnn7 nopservices com on the browser and right click on the page View Page Source I see the following message Have a look at the picture below One question I often get is how to remove that copyright message and the keywords which certainly will be irrelevant with the keywords we want to add for our specific site We login as superuser to our DNN site and then choose Host Host Settings Have a look at the picture below Then I choose Basic Settings then Appearance There is a setting Show Copyright Credits which is checked We must uncheck this option and click Update Have a look at the picture below When I view my website again and then right click on the page View Page Source I do not see either the DNN copyright message or the keywords which were specific to DNN Have a look at the picture below Please note that you can follow these steps for your DNN 6 0 website Hope it helps Posted Κυριακή 20 Ιανουαρίου 2013 8 54 μμ από nikolaosk 0 σχόλια Δημοσίευση στην κατηγορία asp net DNN 7 0 dotnetnuke tips and tricks Looking into the ASP Net Web API part 2 This is the second post discussing the ASP Net Web API I will continue building a small ASP Net MVC 4 0 application that I started implementing in my last post You can have a look at the first post here In this hands on example I will show you how to create new footballer items update a new footballer item delete a new footballer item I will also refactor the implementation for the GET operations methods from my last post I will present you with a full CRUD hands on example This will be based in the RESTful WEB API paradigm and its four main HTTP methods GET will retrieve the footballer items from the specified URI PUT updates a resource footballer item at a specified URI POST will create a new resource footballer item DELETE will delete a resource footballer item at a specified URI Let s move on to actually building the application 1 Launch Visual Studio I have named my application WebApi and open the application 2 As I said earlier I will refactor the code I created in the first post Inside the Models folder my class file Footballer cs looks exactly the same public class Footballer public int FootballerID get set public string FirstName get set public string LastName get set public double Weight get set public double Height get set public DateTime JoinedClub get set public string PositionPlayed get set public int GoalsScored get set I need to create a collection of objects footballer objects I will use the Repository Pattern to separate the collection of objects from our service implementation In Solution Explorer right click the Models folder Select Add then select New Item From the available Templates pane select Installed Templates Under C select Code In the list of code templates select Interface Name the interface IFooballerRepository cs The code for the interface implementation follows public interface IFootballerRepository IEnumerable Footballer GetPlayers Footballer GetFooballerById int id Footballer AddFootballer Footballer item void RemoveFootballer int id bool UpdateFootballer Footballer item 3 Now we obviously need to implement this interface We need to add another class to the Models folder named FootballerRepository cs This class will implement the IFootballerRepository interface Add the following implementation public class FootballerRepository IFootballerRepository private List Footballer footballers new List Footballer private int nextId 1 public FootballerRepository footballers Add new Footballer FootballerID 1 FirstName Steven LastName Gerrard Height 1 85 Weight 85 JoinedClub DateTime Parse 12 12 1999 PositionPlayed Attacking Midfielder GoalsScored 23 footballers Add new Footballer FootballerID 2 FirstName Jamie LastName Garragher Height 1 89 Weight 89 JoinedClub DateTime Parse 12 02 2000 PositionPlayed Central Defender GoalsScored 2 footballers Add new Footballer FootballerID 3 FirstName Luis LastName Suarez Height 1 72 Weight 73 JoinedClub DateTime Parse 12 01 2012 PositionPlayed Striker GoalsScored 27 public IEnumerable Footballer GetPlayers return footballers public Footballer GetFooballerById int id return footballers Find f f FootballerID id public Footballer AddFootballer Footballer item if item null throw new ArgumentNullException item item FootballerID nextId footballers Add item return item public void RemoveFootballer int id footballers RemoveAll f f FootballerID id public bool UpdateFootballer Footballer item if item null throw new ArgumentNullException item int index footballers FindIndex f f FootballerID item FootballerID if index 1 return false footballers RemoveAt index footballers Add item return true Let me explain the implementation above I create a generic collection of Fooballer objects footballers private List Footballer footballers new List Footballer Then I populate the list with objects that live in the computer s memory public FootballerRepository footballers Add new Footballer FootballerID 1 FirstName Steven LastName Gerrard Height 1 85 Weight 85 JoinedClub DateTime Parse 12 12 1999 PositionPlayed Attacking Midfielder GoalsScored 23 footballers Add new Footballer FootballerID 2 FirstName Jamie LastName Garragher Height 1 89 Weight 89 JoinedClub DateTime Parse 12 02 2000 PositionPlayed Central Defender GoalsScored 2 footballers Add new Footballer FootballerID 3 FirstName Luis LastName Suarez Height 1 72 Weight 73 JoinedClub DateTime Parse 12 01 2012 PositionPlayed Striker GoalsScored 27 Well I trust you have some knowledge of C and collection initializers which is a C 3 0 feature Have a look here if you want to learn more about it The individual object initializers are enclosed in braces and separated by commas Next I implement two simple methods GetPlayers returns a list of players GetFooballerById int id returns a single footballer by its ID public IEnumerable Footballer GetPlayers return footballers public Footballer GetFooballerById int id return footballers Find f f FootballerID id Next I am implementing the AddFootballer method which is pretty straightforward method If there is no item object we throw an exception If there is an item we give it a new ID and add the object to the collection public Footballer AddFootballer Footballer item if item null throw new ArgumentNullException item item FootballerID nextId footballers Add item return item Next I am implementing the RemoveFootballer method I just remove an object from the collection with a specific id public void RemoveFootballer int id footballers RemoveAll f f FootballerID id Finally I implement the UpdateFootballer method If there is no item object we throw an exception Then I find the index of the object in the collection array according to its ID and then remove it and add the new one public bool UpdateFootballer Footballer item if item null throw new ArgumentNullException item int index footballers FindIndex f f FootballerID item FootballerID if index 1 return false footballers RemoveAt index footballers Add item return true 4 Now we need to change the code we have written for our controller FootballerController cs in the Controllers folder Comment everything inside this class and just leave the code below public class FootballerController ApiController The complete implementation follows public class FootballerController ApiController static readonly IFootballerRepository repository new FootballerRepository public IEnumerable Footballer GetPlayers return repository GetPlayers public Footballer GetFooballerById int id var footballer repository GetFooballerById id if footballer null throw new HttpResponseException HttpStatusCode NotFound return footballer public HttpResponseMessage PostFootballer Footballer footballer footballer repository AddFootballer footballer var response Request CreateResponse Footballer HttpStatusCode Created footballer string uri Url Link DefaultApi new id footballer FootballerID response Headers Location new Uri uri return response public void PutFootballer int id Footballer footballer footballer FootballerID id if repository UpdateFootballer footballer throw new HttpResponseException HttpStatusCode NotFound public void DeleteFootballer int id Footballer footballer repository GetFooballerById id if footballer null throw new HttpResponseException HttpStatusCode NotFound repository RemoveFootballer id In ASP NET Web API a controller is a class that handles HTTP requests from the client Now I will explain what I have implemented in this class and what methods have been created I am adding a field that holds an IFootballerRepository instance static readonly IFootballerRepository repository new FootballerRepository This is the method to get a list of footballers Well nothing really to explain here public IEnumerable Footballer GetPlayers return repository GetPlayers This is the method to get a footballer item by id This method name also starts with Get This method has a parameter named id This parameter is mapped to the id segment of the URI path The method will throw an exception of type HttpResponseException if id is not valid This exception will be translated by Web API as a 404 Not Found error public Footballer GetFooballerById int id var footballer repository GetFooballerById id if footballer null throw new HttpResponseException HttpStatusCode NotFound return footballer Now I would like to explain again how the ASP NET Web API knows how to map URIs to our controller methods The ASP NET Web API framework for each HTTP message decides which controller receives the request by consulting a route table The Web API project contains a default route that you can find in the WebApiConfig cs file api controller id The controller and id are just placeholders controller is matched to the controller name controller in my case is footballer The HTTP request method is matched to the method name This rule applies only to GET POST PUT and DELETE requests api footballer will match the GetPlayers method api footballer 1 will match the GetFooballerById 1 method Next I am implementing the PostFootballer method This will create a new footballer item The new item is created when the client sends a HTTP POST request to the server with the new footballer object in body of the request message public HttpResponseMessage PostFootballer Footballer footballer footballer repository AddFootballer footballer var response Request CreateResponse Footballer HttpStatusCode Created footballer string uri Url Link DefaultApi new id footballer FootballerID response Headers Location new Uri uri return response The way POST requests are getting handled we define a method whose name starts with Post The method takes a parameter of type Footballer The clients to sends to the server a serialized representation of a footballer object using either XML or JSON for the serialization Next we must think of the response code The Web API framework sets the response status code to 200 OK HTTP 1 1 protocol dictated that when a POST request results in the creation of a resource the server should reply with status 201 Created When the server creates a resource it should include the URI of the new resource in the Location header of the response Next I am implementing the PutFootballer method This method will update a footballer item This method name starts with Put which makes the Web API to match it to PUT requests The method takes two parameters the footballer Id and the updated footballer object The id parameter is taken from the URI path and the footballer parameter is deserialized from the request body The ASP NET Web API framework takes simple parameter types from the route Complex types are taken from the request body public void PutFootballer int id Footballer footballer footballer FootballerID id if repository UpdateFootballer footballer throw new HttpResponseException HttpStatusCode NotFound Next I am implementing the DeleteFootballer method We define a method whose name starts with Delete so the Web API matches it to DELETE requests Τhe method has a parameter named id This parameter is mapped to the id segment of the URI path Ιf the footballer object is not found an exception is thrown If the deletion is successful then status code 204 No Content will be returned public void DeleteFootballer int id Footballer footballer repository GetFooballerById id if footballer null throw new HttpResponseException HttpStatusCode NotFound repository RemoveFootballer id In the next and final post in this series I will build the Index cshtml using Knockout which is a JavaScript library that helps developers to create rich responsive displays when a clean underlying data model exists I think that this is enough material for one post and before I implement Index cshtml I must introduce Knockout library to you Hope it helps Posted Σάββατο 12 Ιανουαρίου 2013 5 52 μμ από nikolaosk 0 σχόλια Δημοσίευση στην κατηγορία asp net C Entity framework jquery Code First Visual Studio 2012 ASP NET MVC 4 0 ASP NET Web Api Looking into the ASP Net Web API part 1 In this post I would like to show you a hands on example on ASP Net Web API by building a small ASP Net application I am going to build an ASP Net MVC 4 0 Web application to create a Web API that returns a list of football players I will also use the popular Javascript library JQuery to issue requests to the server In the second part of this blog post I will show you how to support more operations in an HTTP service like create update delete players using a REST architectural style Before I go on with the actual example I will talk a little bit about REST In 2000 Roy Fielding introduced REpresentational State Transfer in his P H D Thesis It describes a scalable architecture for building services that build on HTTP REST is fundamentally different from SOAP SOAP defines a transport neutral model that is focused on defining custom services contracts with custom operations You can invoke those operations over a variety of different transports using different message encodings REST defines a transport specific HTTP model focused on resources In REST we build services around a uniform interface and common data formats HTTP methods are GET POST PUT DELETE also known as verbs Data formats supported in REST inculde HTML XML JSON REST is also known as a Resource Orientated Architecture The main focus is on identifying and naming resources URIs We also focus on how to represent them XML Format We use uniform interface to interact with those URIs through HTTP verbs GET POST PUT DELETE Through this model we can achieve interoperability and scalability for our applications Web API is a fully extensible framework for building HTTP based endpoints on top of ASP Net It was released with ASP Net MVC 4 0 It is based on ASP Net Routing and but is not linked only to ASP Net MVC You can use it in a Web Forms project as well You can download it through NuGet so you can have the latest version The most important thing right now is to download and install all the tools libary software in your computer so you can follow along You can download all the necessary software tools Visual Studio 2012 Web Edition along with a web server a Sql Server instance libraries binaries if you download Web Platform Installer You can download this tool from this link After you install it you must search for Visual Studio Express 2012 for Web Have a look at the picture below Then click Add and then Install Everything you need will be installed Maybe you need to reboot the machine so do not worry if you will have to do this I have installed Visual Studio 2012 Ultimate edition in my machine which is Windows 8 by the way I have also installed the latest version of Net Framework and I will show you later how to download more libraries when needed I have installed SQL Server 2012 Enterprise Edition in my machine As a Microsoft Certified Trainer I have access to this software but as explained earlier you need only to download Web Platform Installer and then download the Visual Studio Express 2012 for Web and install it Let s start building our ASP Net MVC 4 0 Web application 1 I am launching VS 2012 and I will Visual C as the programming language I will also select ASP NET MVC 4 Web Application from the available templates Have a look at the picture below I have named my application WebApi and then clicked OK 2 From the available templates in the next screen I select Web API This template will create all the necessary files in order to build the application Click OK Have a look at the picture below 3 Have a look at the Solution Explorer to get a feeling of the files being created and the structure of the web application Have a look at the picture below 4 Now we need to add a model that will basically be the data in our application The way everything works is the following We will pass a request to the server an HTTP request message to the server then the server will respond with an HTTP response serializing the model to JSON or XML or any other format On the client side serialized data can be parsed and deserialized Most clients can parse XML and JSON Have a look at the picture below to see the how I add a new model to my application I simply add a class file to my model in the Models folder I name the class Footballer cs The code follows public class Footballer public int FootballerID get set public string FirstName get set public string LastName get set public double Weight get set public double Height get set public DateTime JoinedClub get set public string PositionPlayed get set public int GoalsScored get set 5 We need to add a new controller that basically will handle the HTTP request Add a new controller as follows In Solution Explorer right click the the Controllers folder Select Add and then select Controller Have a look at the picture below In the Add Controller wizard name the controller FootballerController In the Template drop down list select Empty API Controller Then click Add The FootballerController will inherit from the ApiController class and not the Controller class I will add the following methods to the class public class FootballerController ApiController Footballer footballers new Footballer new Footballer FootballerID 1 FirstName Steven LastName Gerrard Height 1 85 Weight 85 JoinedClub DateTime Parse 12 12 1999 PositionPlayed Attacking Midfielder GoalsScored 23 new Footballer FootballerID 2 FirstName Jamie LastName Garragher Height 1 89 Weight 89 JoinedClub DateTime Parse 12 02 2000 PositionPlayed Central Defender GoalsScored 2 new Footballer FootballerID 3 FirstName Luis LastName Suarez Height 1 72 Weight 73 JoinedClub DateTime Parse 12 01 2012 PositionPlayed Striker GoalsScored 27 public IEnumerable Footballer GetPlayers return footballers public Footballer GetFooballerById int id var footballer footballers FirstOrDefault f f FootballerID id if footballer null throw new HttpResponseException HttpStatusCode NotFound return footballer public IEnumerable Footballer GetFooballersByPosition string position return footballers Where f string Equals f PositionPlayed position StringComparison OrdinalIgnoreCase All my data is stored in an array in memory We have 3 methods that return data and not view inside the controller class GetPlayers returns a list of players GetFooballerById int id returns a single footballer by its ID GetFooballersByPosition string position returns all football players according to their playing position Each method on the controller will map to a URI The client in this case the web browser will send an HTTP GET request to the URI 6 Build and run you application The IIS Express will start and a notification will appear in the bottom corner of the screen showing the port number that it is running under A random port number will be selected You will see the default page In my case is http localhost 57865 Now I must invoke the web API so must use the following URI http localhost 57865 api footballer Have a look below to see what I see when I view the page in Firefox It is displayed in XML in the browser 7 Now we need to test the other two methods The first one will return a footballer by ID and the second one will return data based on the player s playing position While my application is still running I type in the browser http localhost 57865 api footballer 1 and hit enter Have a look at the picture below to see the results I get in Firefox While my application is still running I type in the browser http localhost 57865 api footballer position Attacking 20Midfielder and hit enter Have a look at the picture below to see the results I get in Firefox 8 I will write a small client application a javascript client in order to consume the APIs I will modify the Index cshtml file in the Views folder I will not be using Razor in this post I will only use plain HTML 5 and Javascript The contents of the Index chstml follow DOCTYPE html html lang en head title ASP NET Web API title link href Content Site css rel stylesheet script src Scripts jquery 1 7 1 min js type text javascript script script type text javascript document ready function getJSON api footballer function data each data function key val var str val FirstName val LastName li text str appendTo footballers script head body id body div class main div h1 All Footballers h1 ul id footballers div div label for FootballerId ID label input type text id FootballerId size 5 input type button value Search onclick find p id footballer div div body html Let me explain what I am doing here There is a link to JQuery library at the top of the script I have an HTML 5 markup where I will present the footballers eventually With the command below I am sending an Ajax request to the server The getJSON command does that The response will be an array of JSON objects When the request successfully completes see code below each data function key val var str val FirstName val LastName li text str appendTo footballers getJSON api footballer the data will be returned formatted When I build and run the application this is what I get My application works I can see what actually is going on behind the scenes if I have the right tool Fiddler is a web debugging proxy tool and you can use it to see all useful information the clients and servers exchange You can download Fiddler here In my case I am mostly interested in the JSON objects returned from the server Have a look at the picture below 9 Now I will show you how to find a footballer by id The code for the find method is function find var id FootballerId val getJSON api footballer id function data var str data FirstName data LastName footballer text str fail function jqXHR textStatus err footballer text Error err We make a call to the jQuery getJSON function to send the AJAX request We use the ID to construct the request URI The response from this request is a JSON representation of a single Footballer object Have a look at the picture below If I enter an invalid ID in the search box then I get back an HTTP error Have a look at the picture below Now I need to explain how the ASP NET Web API knows how to map URIs to our controller methods The ASP NET Web API framework for each HTTP message decides which controller receives the request by consulting a route table The Web API project contains a default route that you can find in the WebApiConfig cs file api controller id The controller and id are just placeholders controller is matched to the controller name controller in my case is footballer The HTTP request method is matched to the method name This rule applies only to GET POST PUT and DELETE requests api footballer will match the GetPlayers method api footballer 1 will match the GetFooballerById 1 method We have a GET request so the framework looks for a method on FootballerController controller So there will be a call to the FootballerController controller and for a method whose name starts with Get The FootballerController GetPlayers method will execute When we pass a parameter id to the controller the frameworks call the GetFooballerById which takes the parameter and returns the footballer object The complete code for the Index cshtml follows DOCTYPE html html lang en head title ASP NET Web API title link href Content Site css rel stylesheet script src Scripts jquery 1 7 1 min js type text javascript script script type text javascript document ready function getJSON api footballer function data each data function key val var str val FirstName val LastName li text str appendTo footballers function find var id FootballerId val getJSON api footballer id function data var str data FirstName data LastName footballer text str fail function jqXHR textStatus err footballer text Error err script head body id body div class main div h1 All Footballers h1 ul id footballers div div label for FootballerId ID label input type text id FootballerId size 5 input type button value Search onclick find p id footballer div div body html In the second part next blog post I will be extending the application to insert update and delete information Hope it helps Posted Πέμπτη 10 Ιανουαρίου 2013 12 40 πμ από nikolaosk 0 σχόλια Δημοσίευση στην κατηγορία asp net C Entity framework jquery Code First Visual Studio 2012 ASP NET MVC 4 0 ASP NET Web Api Looking into Transaction Log size and clearing and database backups In this post I would like to talk about the size of the transaction log and under what circumstances it clears in relation to recovery models and database backup types Full Differential Log I will also give a brief overview of recovery models database backup types read more Posted Παρασκευή 4 Ιανουαρίου 2013 9 53 μμ από το μέλος nikolaosk 0 σχόλια Δημοσίευση στην κατηγορία SQL Server 2008 Sql Server 2005 Sql Server transaction log sql server 2012 Creating a complete ASP Net MVC 4 0 application with Visual Studio 2012 C EF 5 0 Code First part 6 I have decided to write a series of posts on how to write a small ASP Net MVC 4 0 application I will develop this application step by step and I will explain everything that you need to know in order to develop ASP Net MVC 4 0 applications This is the sixth post in this series You can find the first one here the second one here third one here the fourth one here and the fifth one here Make sure you read and understand those posts In this post I will add some validations to our application through Code First Data Annotations and migrate those changes to our database through EF Code First Migrations Right now there is no validation for the fields Rating and Comment of the MovieReview entity I want to have a validation rule applied to the Rating field that will accept only values 1 to 10 and it will be mandatory The Comment field will only be 100 characters long and also mandatory We also want to have the characters for the Name property of the Movie entity restricted to 70 and the name of the Director restricted to 50 characters Both of these properties should be mandatory I am going briefly to introduce Data Annotations and how to use them in our Code First Entity framework applications I have developed my data access layer with EF We have 3 development paradigms in EF We have Database First Model First and Code First The last one Code First is the one I have used for this application and frankly speaking it is gaining in popularity amongst developers I will use another post also found in this blog to demonstrate Data Annotations In order to fully understand what I am talking about you need to read this post titled Using the Code First approach when building ASP Net applications with Entity Framework It will take some time to create this application but it is necessary in order to follow along With Data Annotations we can configure our domain entity classes so that they can take best advantage of the EF We can decorate our entity classes with declarative attributes Let me give you an insight on how EF Code First works EF Code First at run time looks at the entity domain classes and infers from them the in memory data that it needs to interpret the queries and interact with the database For example it assumes that any property named ID represents the key property of the class Data Annotations live inside the System ComponentModel DataAnnotations We do add Data Annotations to our domain classes declaratively using attributes You can also do that imperatively using the Fluent API 1 Launch Visual Studio and launch the ASP Net MVC 4 0 application we have been developing so far 2 Have a look at my entity class Movie public class Μovie public int Id get set public string Name get set public string Director get set public DateTime YearReleased get set public virtual ICollection MovieReview Reviews get set If I go to the entity above and make one little change renaming the public string Name get set to Required MaxLength 70 public string Name get set my application will get an error if compile and view it in a browser It will compile but when I click on the Movie link on the menu I get the results shown in the following picture 3 Make sure you add a reference to the System ComponentModel DataAnnotations namespace in the class file using System ComponentModel DataAnnotations Both entities after applying the data annotation attributes follow public class Μovie public int Id get set Required MaxLength 70 public string Name get set Required MaxLength 50 public string Director get set public DateTime YearReleased get set public virtual ICollection MovieReview Reviews get set public class MovieReview public int Id get set Required Range 1 10 public int Rating get set Required MaxLength 50 public string Comment get set public int MovieId get set There are other data annotation attributes like Key ConcurrencyCheck Table MyTable Schema guest but it is impossible to cover everything in this post Now I am compiling again my application and then when I click on the Movie link on the menu I get the results shown in the following picture So we receive an error Well there is an explanation for that behavior The Entity Framework always checks the model that is in effect that we just configured against the model it used originally to create the database 4 The Entity Framework detected that there is something different in this model When we apply the Required attribute to an property in the entity then this field in the database should be not null In order to solve that problem we must apply Code First Migrations Code First Migrations is an Entity Framework feature introduced in version 4 3 back in February of 2012 Before the addition of Code First Migrations 4 1 4 2 versions Code First database initialisation meant that Code First would create the database if it does not exist the default behaviour CreateDatabaseIfNotExists The other pattern we could use is DropCreateDatabaseIfModelChanges which means that Entity Framework will drop the database if it realises that model has changes since the last time it created the database The final pattern is DropCreateDatabaseAlways which means that Code First will recreate the database every time one runs the application That is of course fine for the development database but totally unacceptable and catastrophic when you have a production database We cannot lose our data because of the way that Code First works Migrations solve this problem With migrations we can modify the database without completely dropping it We can modify the database schema to reflect the changes to the model without losing data 5 EF Code First Migrations is not activated by default We have to activate them manually and configure them according to our needs We will open the Package Manager Console from the Tools menu within Visual Studio Then we will activate the EF Code First Migration Features by writing the command Enable Migrations Have a look at the picture below This adds a new folder Migrations in our project A new auto generated class Configuration cs is created Another class is also created CURRENTDATE InitialCreate cs and added to our project The Configuration cs is shown in the picture below 6 Now we need to update the database In the Configurations cs I change the AutomaticMigrationsEnabled value to true public Configuration AutomaticMigrationsEnabled true Then in the Package Manager Console we write the following Update Database Verbose This will fail because EF understands that we take a column that was nvarchar max and make it nvarchar 50 e t c Then in the Package Manager Console we write the following Update Database Verbose Force This statement will succeed That will force the changes to the database Have a look at the picture below As you can see all the changes were made to the database Now if we run again our application and test it try to violate the 1 10 values allowed in the rating field I will get the error shown in the picture below I know we covered a lot in this post but you must understand it if you want to master EF Code First Hope it helps Posted Τετάρτη 2 Ιανουαρίου 2013 1 17 πμ από nikolaosk 0 σχόλια Δημοσίευση στην κατηγορία asp net C CSS Entity framework jquery HTML Code First Visual Studio 2012 ASP NET MVC 4 0 Creating a complete ASP Net MVC 4 0 application with Visual Studio 2012 C EF 5 0 Code First part 5 I have decided to write a series of posts on how to write a small ASP Net MVC 4 0 application I will develop this application step by step and I will explain everything that you need to know in order to develop ASP Net MVC 4 0 applications This is the fourth post in this series You can find the first one here the second one here the third one here and the fourth one here Make sure you read and understand those posts In this post I will add Search functionality to my application and 1 Launch Visual Studio and open the application 2 We must add code to the Layout cshtml view in the Shared folder and more specifically to the menu We must add an entry so someone can navigate to the Movie View The nav section becomes like this nav ul id menu li Html ActionLink Home Index

    Original URL path: http://www.dotnetzone.gr/cs/blogs/dotnetrules/default.aspx?p=2 (2015-07-15)
    Open archived version from archive

  • Rocking with Knowledge for .NET programming : Contact
    Windows 7 Windows Server 2008 Πλοήγηση Αρχική σελίδα Εκδηλώσεις Ιστολόγια Συζητήσεις Εκθέσεις Φωτογραφιών Αρχειοθήκες My Other Blogs for SQL Server and databases Διάφορα Links European Mediterranean Seismological Centre Ιστορικό Δημοσιεύσεων Ιούνιος 2015 1 Σεπτέμβριος 2014 1 Ιούνιος 2014 2 Μάρτιος 2014 2 Φεβρουάριος 2014 4 Ιανουάριος 2014 5 Δεκέμβριος 2013 1 Σεπτέμβριος 2013 2 Αύγουστος 2013 5 Ιούλιος 2013 1 Ιούνιος 2013 1 Μάιος 2013 3 Απρίλιος 2013 4 Μάρτιος

    Original URL path: http://www.dotnetzone.gr/cs/blogs/antonch/contact.aspx (2015-07-15)
    Open archived version from archive

  • Rocking with Knowledge for .NET programming : Is it possible to Join a table with a stored procedure?
    0 Azure BCM 2007 Certifications Cloud Computing ebook IE8 msdn MVP Program Spec Explorer Vedea Visual Studio 2005 Visual Studio 2008 Visual Studio 2010 Windows 7 Windows Server 2008 Πλοήγηση Αρχική σελίδα Εκδηλώσεις Ιστολόγια Συζητήσεις Εκθέσεις Φωτογραφιών Αρχειοθήκες My Other Blogs for SQL Server and databases Διάφορα Links European Mediterranean Seismological Centre Ιστορικό Δημοσιεύσεων Ιούνιος 2015 1 Σεπτέμβριος 2014 1 Ιούνιος 2014 2 Μάρτιος 2014 2 Φεβρουάριος 2014 4 Ιανουάριος 2014 5 Δεκέμβριος 2013 1 Σεπτέμβριος 2013 2 Αύγουστος 2013 5 Ιούλιος 2013 1 Ιούνιος 2013 1 Μάιος 2013 3 Απρίλιος 2013 4 Μάρτιος 2013 3 Φεβρουάριος 2013 3 Ιανουάριος 2013 7 Νοέμβριος 2012 2 Οκτώβριος 2012 6 Σεπτέμβριος 2012 7 Αύγουστος 2012 7 Ιούλιος 2012 7 Ιούνιος 2012 2 Μάιος 2012 1 Ιανουάριος 2012 1 Νοέμβριος 2011 5 Οκτώβριος 2011 4 Σεπτέμβριος 2011 5 Μάρτιος 2011 1 Ιανουάριος 2011 1 Μάρτιος 2010 1 Φεβρουάριος 2010 1 Ιανουάριος 2010 1 Δεκέμβριος 2009 1 Νοέμβριος 2009 5 Οκτώβριος 2009 1 Αύγουστος 2009 2 Ιούλιος 2009 1 Ιούνιος 2009 3 Σεπτέμβριος 2008 1 Αύγουστος 2008 1 Ιούλιος 2008 1 Φεβρουάριος 2008 2 Ιανουάριος 2008 5 Δεκέμβριος 2007 4 Ιούλιος 2007 1 Μάιος 2007 1 Δεκέμβριος 2006 1 Οκτώβριος 2006 1 Is it

    Original URL path: http://www.dotnetzone.gr/cs/blogs/antonch/archive/2014/09/27/is-it-possible-to-join-a-table-with-a-stored-procedure.aspx (2015-07-15)
    Open archived version from archive



  •