在创建Code First Entity框架的新数据库上加载表

时间:2016-10-09 04:34:47

标签: c# entity-framework ef-code-first

我是C#.Net Entity框架的新手。感谢您的建议。要求是采用代码优先方法,检查数据库是否存在,如果不是基于Model类创建数据库和表,则使用数据加载表。此加载应仅在第一次创建表时发生。您能为我提出一些教程,以满足上述要求吗?我搜索了现有的问题但找不到任何东西。

提前致谢。

1 个答案:

答案 0 :(得分:0)

您可以尝试如下所示。

// Here, thisActivity is the current activity
if (ContextCompat.checkSelfPermission(thisActivity,
            Manifest.permission.ACCESS_FINE_LOCATION)
    != PackageManager.PERMISSION_GRANTED) {

// Should we show an explanation?
if (ActivityCompat.shouldShowRequestPermissionRationale(thisActivity,
        Manifest.permission.ACCESS_FINE_LOCATION)) {

    // Show an expanation to the user *asynchronously* -- don't block
    // this thread waiting for the user's response! After the user
    // sees the explanation, try again to request the permission.

} else {

    // No explanation needed, we can request the permission.

    ActivityCompat.requestPermissions(thisActivity,
            new String[]{Manifest.permission.ACCESS_FINE_LOCATION},
            MY_PERMISSIONS_REQUEST_LOCATION);

    // MY_PERMISSIONS_REQUEST_LOCATION is an
    // app-defined int constant. The callback method gets the
    // result of the request.
} else{
 // Run your async task here(you have got location permission already)
 new GetLocationTask(Activity).execute();
}

您可以在此处详细了解:Database Initialization Strategies in Code-First