ASP.NET Core – Existing Database


The following prerequisites are needed to complete this walkthrough:


Blogging database

This tutorial uses a Blogging database on your LocalDb instance as the existing database.


If you have already created the Blogging database as part of another tutorial, you can skip these steps.

  • Open Visual Studio
  • Tools -> Connect to Database…
  • Select Microsoft SQL Server and click Continue
  • Enter (localdb)\mssqllocaldb as the Server Name
  • Enter master as the Database Name and click OK
  • The master database is now displayed under Data Connections in Server Explorer
  • Right-click on the database in Server Explorer and select New Query
  • Copy the script, listed below, into the query editor
  • Right-click on the query editor and select Execute

Create a new project

  • Open Visual Studio 2017
  • File -> New -> Project…
  • From the left menu select Installed -> Templates -> Visual C# -> Web
  • Select the ASP.NET Core Web Application (.NET Core) project template
  • Enter EFGetStarted.AspNetCore.ExistingDb as the name and click OK
  • Wait for the New ASP.NET Core Web Application dialog to appear
  • Under ASP.NET Core Templates 1.1 select the Web Application
  • Ensure that Authentication is set to No Authentication
  • Click OK

Install Entity Framework

To use EF Core, install the package for the database provider(s) you want to target. This walkthrough uses SQL Server. For a list of available providers see Database Providers.1

    • Tools -> NuGet Package Manager -> Package Manager Console
    • Run Install-Package Microsoft.EntityFrameworkCore.SqlServer


We will be using some Entity Framework Tools to create a model from the database. So we will install the tools package as well.

  • Run Install-Package Microsoft.EntityFrameworkCore.Tools
  • Run Install-Package Microsoft.EntityFrameworkCore.SqlServer.Design

Reverse engineer your model

Now it’s time to create the EF model based on your existing database.

    • Tools –> NuGet Package Manager –> Package Manager Console
    • Run the following command to create a model from the existing database. If you receive an error stating The term 'Scaffold-DbContext' is not recognized as the name of a cmdlet, then close and reopen Visual Studio.



The reverse engineer process created entity classes (Blog.cs & Post.cs) and a derived context (BloggingContext.cs) based on the schema of the existing database.

The entity classes are simple C# objects that represent the data you will be querying and saving.


The context represents a session with the database and allows you to query and save instances of the entity classes.


Register your context with dependency injection

The concept of dependency injection is central to ASP.NET Core. Services (such as BloggingContext) are registered with dependency injection during application startup. Components that require these services (such as your MVC controllers) are then provided these services via constructor parameters or properties. For more information on dependency injection see the Dependency Injection article on the ASP.NET site.

Remove inline context configuration

In ASP.NET Core, configuration is generally performed in Startup.cs. To conform to this pattern, we will move configuration of the database provider to Startup.cs.

  • Open Models\BloggingContext.cs
  • Delete the OnConfiguring(...) method

  • Add the following constructor, which will allow configuration to be passed into the context by dependency injection

Register and configure your context in Startup.cs

In order for our MVC controllers to make use of BloggingContext we are going to register it as a service.

  • Open Startup.cs
  • Add the following using statements at the start of the file

Now we can use the AddDbContext(...) method to register it as a service.

  • Locate the ConfigureServices(...) method
  • Add the following code to register the context as a service


In a real application you would typically put the connection string in a configuration file. For the sake of simplicity, we are defining it in code. For more information, see Connection Strings.

Create a controller

Next, we’ll enable scaffolding in our project.

  • Right-click on the Controllers folder in Solution Explorer and select Add -> Controller…
  • Select Full Dependencies and click Add
  • You can ignore the instructions in the ScaffoldingReadMe.txt file that opens

Now that scaffolding is enabled, we can scaffold a controller for the Blog entity.

    • Right-click on the Controllers folder in Solution Explorer and select Add -> Controller…
    • Select MVC Controller with views, using Entity Framework and click Ok
    • Set Model class to Blog and Data context class to BloggingContext
    • Click Add


Run the application

You can now run the application to see it in action.

  • Debug -> Start Without Debugging
  • The application will build and open in a web browser
  • Navigate to /Blogs
  • Click Create New
  • Enter a Url for the new blog and click Create



Deep Learning


How to remove Day in DatePickerDialog in Xamarin Android


Forcing Firefox to obey autocomplete=”off” for password fields

From Jason Hinkle’s Blog

This is a very old article. Again I should stress that the point of this trick is not to wipe out the saved password for login forms. I use it for registration forms and preferences pages that allow users to change their password.  In these cases, auto-filling the password can cause problems for the user.  This is not a security fix.

I have a new technique now which is much simpler.  Create a hidden “honeypot” password field at the top of your form. Browser auto-complete features will only fill in the first password field that they hit. So, by having a dummy password field at the top of your form, you can trick the browser into filling out that field instead of the real password field. It looks like this:


Autocomplete is a nice feature which fills in common form fields automatically for the user. However, in some cases you don’t want this to happen.  Some examples could be an account management page where you don’t want the admin password to be auto-filled in when you are creating and managing accounts.  Another example is any site that has a “My Account” page with a field allowing you to change your password.  Auto-complete can accidentally fill in these fields because it thinks it is a login form.

IE uses a non-standard attribute (autocomplete=”off”) that can be added to an entire form or one specific input control. Besides the fact that this attribute will make your HTML markup fail compliance tests, Firefox seems to consider this tag merely a “suggestion” and will disregard it at times.

In particular, Firefox will *always* populate certain password fields. There is seemingly no way to tell Firefox not to fill in a field if it really wants to do so. This can be a very bad thing if you are dealing with a user preference page or something sensitive where you don’t want autocomplete to ever occur under any circumstance. Setting value=”” is equally worthless because Firefox seems to populate this value just after the page is rendered.

The following code however will work. The concept is basically to set a timeout a fraction of a second after the page loads which clears the password field. Technically Firefox still populates the field, however this script code removes it almost instantly. As an added bonus, because you are not using autocomplete=”off” your HTML markup should still validate. This code should be placed at the bottom of your page beneath your form.

This code could probably be made more generic by enumerating through the form elements and searching for a certain class name. This way you could have one script and simply append a classname to any field that you don’t want auto-complete to occur. This technique is similar to one posted on Chris Holland’s blog. Chris’s solution, however, is aimed exclusively at the Wc3 compliance issue. As you can see in his code he adds the autocomplete=”off” attribute, which allows the page to validate properly, but doesn’t solve the Firefox/Password field issue.

If you have a more graceful solution and/or decide to flesh this idea out, please post a comment and I’ll provide a link to your site.


How to delete duplicate rows in sql server?


Query and update an Excel 2010 spreadsheet via a linked server

First  I downloaded and installed the ‘AccessDatabaseEngine_x64.exe’ file on the SQL Server from No restart was required.

Next I started SQL Server Management Studio as ‘Administrator’.



Next I enabled the ‘Allow inprocess’ option for the Microsoft.ACE.OLEDB.12.0 provider.



The linked server was created with this script:

IOS design layout , icon , size ….

Resolutions and Display Specifications

Device Retina Portrait (px) Landscape (px)
iPhone 6+ Retina HD 1080 x 1920 1920 x1080
iPhone 6 Retina 750 x 1334 1334 x 750
iPhone 55, 5S, 5C Retina 640 x 1136 1136 x 640
iPhone 44, 4S Retina 640 x 960 960 x 640
iPhone1st, 2nd & 3rd Generation No 320 x 480 480 x 320
iPad Air / Retina iPad1st & 2nd Generation / 3rd & 4th No 1536 x 2048 2048 x 1536
iPad Mini2nd & 3rd Generation Retina 1536 x 2048 2048 x 1536
iPadMini, 1st & 2nd Generation No 768 x 1024 1024 x 768


Device Asset Resolution PPI Display Size
iPhone 6+ @3x 401 5.5″
iPhone 6 @2x 326 4.7″
iPhone 55, 5S, 5C @2x 326 4.0″
iPhone 44, 4S @2x 326 3.5″
iPhone1st, 2nd & 3rd Generation @1x 163 3.5″
iPad Air / Retina iPad1st & 2nd Generation/ 3rd & 4th @2x 264 9.7″
iPad Mini2nd & 3rd Generation @2x 326 7.9″
iPad Mini1st Generation @1x 163 7.9″
iPad1st & 2nd Generation @1x 132 9.7″

App Icons

Device App Icon AppStore Icon Spotlight Settings
iPhone 6+ 180×180 px 1024×1024 px 120×120 px 87×87 px
iPhone6, 5S, 5, 5C, 4S, 4 120×120 px 1024×1024 px 80×80 px 58×58 px
Old iPhones1st, 2nd, 3rd Generation 57×57 px 1024×1024 px 29×29 px 29×29 px
Retina iPadsMini 2 & 3, Air, 3 & 4 152×152 px 1024×1024 px 80×80 px 58×58 px
Old iPads1, 2, Mini 1 76×76 px 1024×1024 px 40×40 px 29×29 px

Icon dimensions for iOS 8 apps:

Name Size (px) Usage
Icon-Small.png 29×29 iPad Settings
Icon-Small@2x.png 58×58 iPhone Settings, iPad Settings for Retina display
Icon-Small@3x.png 87×87 iPhone Settings for Retina display
Icon-40.png 40×40 iPad Spotlight results
Icon-40@2x.png 80×80 iPhone Spotlight results, iPad Spotlight results for retina display
Icon-40@3x.png 120×120 iPhone Spotlight results for retina display
Icon-60@2x.png 120×120 iPhone App Icon
Icon-60@3x.png 180×180 iPhone App Icon for Retina display
Icon-76.png 76×76 iPad App Icon
Icon-76@2x.png 152×152 iPad App Icon for Retina display
Icon-120.png 120×120 CarPlay App Icon
iTunesArtwork.png 512×512 App Submission
iTunesArtwork@2x.png 1024×1024 App Submission

FTPS with C#

This post will show how to upload , download a file via FTPS protocol with C#

Open Nuget manager , search for AlexFTPS package, then add it into your project .

This function below demo how to use it :