Showing posts with label EntityFramework. Show all posts
Showing posts with label EntityFramework. Show all posts

Thursday, 5 December 2013

Microsoft Virtual Academy - ASP.NET MVC

I’ve just got into the Microsoft Virtual Academy, and I have to say it has a wealth of up to date, excellent training videos.

http://www.microsoftvirtualacademy.com/Content/ViewContent.aspx?et=4099&m=4093&ct=19601#?fbid=_Oyn-vcRqgr

Razor syntax escape characters…

image

Html anti forgery token..

http://blog.stevensanderson.com/2008/09/01/prevent-cross-site-request-forgery-csrf-using-aspnet-mvcs-antiforgerytoken-helper/

ASP.NET MVC 4 Content Map

http://www.asp.net/mvc/overview/getting-started/aspnet-mvc-content-map

Script including - always use the longhand version for the <script></script> tag, otherwise your script file will not be downloading to the client browser

JSBin.com - http://jsbin.com/ a fantastic javscript, jquery, html and css online playground like jsfiddle.net and plnkr.co. The nice thing about this one though is that you can download the entire finished article file as a single html page.

What's coming in ASP.NET - www.asp.net/vnext

Signed nightly builds of asp.net vnext - https://aspnetwebstack.codeplex.com/

Getting started with web api - http://www.asp.net/web-api/overview/getting-started-with-aspnet-web-api/tutorial-your-first-web-api

Web API 2 (video) - http://channel9.msdn.com/Events/Build/2013/3-504

Thursday, 13 December 2012

How to use the Translator Generator VS 2010 Extension

Installation

  1. Ensure you have the following installed...
    a)http://www.microsoft.com/en-us/download/details.aspx?id=21835
    b)http://visualstudiogallery.msdn.microsoft.com/25e4b5e9-65e4-4950-967d-5f1e6a9dcbeb/?lc=1033 - simply double click the downloaded vsix file
  2. Install the TranslatorGenerator VSIX package by double clicking on it. You will see the following window appear, just click the Install button.
    image
  3. If you have successfully installed you will see the following message...
    image

 

Enabling the Translator Generator

  1. Open your solution in visual studio 2010
  2. Enable the translator generator from Tools, Guidance Package Manager, Enable / Disable Packages..., check Translator Generator option, OK
    image

 

Using the Translator Generator

  1. Open a new Visual Studio instance after installing the package
  2. Right click on your target project and select Create Translator from the Translator Generator context menu option
    image
  3. Click the ... buttons to choose your first and second classes, which are your source and target entities that you wish to create translator logic for
    image
  4. Then click the Next button
  5. Now click the Map All button, this will attempt to match up similar named properties (case insensitive, and underscore characters ignored)
    image
  6. You can then select properties manually in each side and click the map button to line these up as well
    image
    image
  7. Then click the finish button. Your newly created translator will end up under the Translators folder in your project.

Uninstalling

  1. Run the following command from a VS.NET command prompt window
    VSIXInstaller.exe /U:8E53EB18-6A5C-4068-B24F-DE7147F3BB3E
  2. You should then see this window
    image
  3. Then restart visual studio to ensure the package is completely removed from your extensions folder which is under

    %userprofile%\AppData\Local\Microsoft\VisualStudio\10.0\Extensions

Friday, 28 September 2012

How to create the DataContracts and Translators for Entity Framework generated objects

Think I've just come up with a fool proof method for creating datacontracts and associated translator logic from Entity Framework generated objects

Creating datacontracts

1. Grab the class definition from the xxxModel.cs file in xxxx.DataContracts.csproj project

2. Paste into a new file in the xxx.DataContracts namespace

3. Use Resharper to clean up the code (Ctrl +E , Ctrl + C), choose full format option

4. Suspend off Resharper (Tools, options ,Resharper)

5. Grab the primitives section and change privates to publics

6. Replace ; with { get; set; } and then replace _ with empty string

7. That's it, you now have your matching datacontract with no typos and property names matching the auto generated ones in the xxxModel.cs file.

Creating translators (little bit more involved) method

1. Use the following regex replace expression on the pasted properties from the class you created above.

Remember to paste them from the datatype definition onwards, and put them at the start of the line in the mapping class first! e.g.

String Author { get; set; }
String DMlibraryName { get; set; }
DateTime? DateCreated { get; set; }
String DocNAME { get; set; }
int? DocNumber { get; set; }
String DocPath { get; set; }
String DocTypeCode { get; set; }
String DocTypeDescription { get; set; }
Int32 IsDMType { get; set; }
Int32 IsRRAKMANType { get; set; }
int? PersonID { get; set; }
int? ProjectID { get; set; }
String ProjectLabel { get; set; }
String htmlLocation { get; set; }

Find: ^([a-zA-Z_$][a-zA-Z0-9_$?]*):b{(.*)}\{(.*)
Replace with: source.\1 = dest.\1;

Result is as follows...

source.Author  = document.Author;
source.DMlibraryName  = document.DMlibraryName;
source.DateCreated  = document.DateCreated;
source.DocNAME  = document.DocNAME;
source.DocNumber  = document.DocNumber;
source.DocPath  = document.DocPath;
source.DocTypeCode  = document.DocTypeCode;
source.DocTypeDescription  = document.DocTypeDescription;
source.IsDMType  = document.IsDMType;
source.IsRRAKMANType  = document.IsRRAKMANType;
source.PersonID  = document.PersonID;
source.ProjectID  = document.ProjectID;
source.ProjectLabel  = document.ProjectLabel;
source.htmlLocation  = document.htmlLocation;

(Old Creating translators (little bit more involved) method)

1. Turn resharper back on

2. Use the File Structure window

clip_image001

3. Stick this in Excel and do some manipulation (ask me if you're not sure how to do this)

clip_image002

4. Paste this back into your C# file, and do a regex replace of \t with nothing

5. That's it, translator code written

How to find the last interactive logons in Windows using PowerShell

Use the following powershell script to find the last users to login to a box since a given date, in this case the 21st April 2022 at 12pm un...