Wednesday, December 27, 2017

Delete existing database and recreate it by EntityFramework code first for asp.net core project

1. Delete the existing database
option 1: From the Visual Studio's View->SQL Server Object Explorer, delete the existing database. Note, just delete the database file from disk is not enough, as the table is still kept in system table list.
option 2: from command line, run
dotnet ef database drop

2. Delete all files from asp.net project's Migrations folder

3. From command line, run the below command to add the migration cs script to the asp.net core project
dotnet ef migrations add initial

4.Create the database and table
option 1:  From the command line, run the below command to
dotnet ef database update

option 2: call Database.Migration method from cs code when starting app. This option is particular useful for Azure deployment with connection settings as command line is not a good option for Azure cloud deployment.
public class Program
    {
        public static void Main(string[] args)
        {
            var host = CreateWebHostBuilder(args).Build();
            
            using (var scope = host.Services.CreateScope()){
                var context = scope.ServiceProvider.GetRequiredService<ApplicationDbContext>();
                context.Database.Migrate();
            }
            host.Run();
        }

        public static IWebHostBuilder CreateWebHostBuilder(string[] args) =>
            WebHost.CreateDefaultBuilder(args)
                .UseStartup<Startup>();
    }
}

Wednesday, December 13, 2017

iOS: set different row height for different prototype cells in a single table view

Since IOS 8.1,  supporting different height for different row prototype is quite easy.

First in storyboard, setting height constraint for different row prototype, then adding those rows into a single UITableView will show the height constraints are ignored at runtime and the row height is always using the row height configured in TableView row height property.

In order to apply the row height constraint defined in row prototype, add the below code in the viewController's viewDidLoad method

        tableView.estimatedRowHeight = 44

        tableView.rowHeight = UITableViewAutomaticDimension

The estimatedRowHeight can be set to the same value as configured in tableview's row height property.

Note, inside the cell, the vertical constraint must set to require the vertical cell height. For example, if a button has top and bottom and height constraints added as the cell height, it will work. But if the button only has top and height constraints, then it will not work, as the cell will be shrunked to estimated row height.

Monday, December 4, 2017

Fix "could not resolve project cordovaLib" error after upgrading to android studio 3.0.1

After upgrading to Android studio 3.0.1, when building cordova project, if error happens for

Unable to resolve dependency for ':@debug/compileClasspath': Could not resolve project :CordovaLib. Open File Show Details

Then it can be fixed by updating the android module's build.gradle with the below change:

dependencies {
    compile fileTree(dir: 'libs', include: '*.jar')
    // SUB-PROJECT DEPENDENCIES START    debugCompile(project(path: "CordovaLib", configuration: "debug"))
    releaseCompile(project(path: "CordovaLib", configuration: "release"))
    compile project(':CordovaLib')
// SUB-PROJECT DEPENDENCIES END
}