我想实现一个自定义数据库初始化策略,以便我可以使用提供的用户ID和密码生成数据库模式并将其应用于EXISTING EMPTY SQL数据库.
不幸的是,内置策略没有提供我正在寻找的东西:
// The default strategy creates the DB only if it doesn't exist - but it does
// exist so this does nothing
Database.SetInitializer(new CreateDatabaseOnlyIfNotExists<DataContext>());
// Drops and re-creates the database but then this breaks my security mapping and
// only works if using a “Trusted" connection
Database.SetInitializer(new RecreateDatabaseIfModelChanges<DataContext>());
// Strategy for always recreating the DB every time the app is run. – no good for
// what I want
Database.SetInitializer(new AlwaysRecreateDatabase<DataContext>());
Run Code Online (Sandbox Code Playgroud)
我已经解决了以下问题,但这不会创建ModelHash,因此我无法使用"context.Database.ModelMatchesDatabase()"来验证是否已创建数据库模式并阻止多次初始化:
public class …Run Code Online (Sandbox Code Playgroud) 我们在swift中创建了一个使用钥匙串的应用程序.该应用程序在设备或模拟器上运行时工作正常,但在通过Testflight配置时无法访问钥匙串,除非配置到以前从未安装过通过Xcode 6.1安装的应用程序的新设备.
以下是钥匙串代码的摘录:
import UIKit
import Security
let serviceIdentifier = "com.ourdomain"
let kSecClassValue = kSecClass as NSString
let kSecAttrAccountValue = kSecAttrAccount as NSString
let kSecValueDataValue = kSecValueData as NSString
let kSecClassGenericPasswordValue = kSecClassGenericPassword as NSString
let kSecAttrServiceValue = kSecAttrService as NSString
let kSecMatchLimitValue = kSecMatchLimit as NSString
let kSecReturnDataValue = kSecReturnData as NSString
let kSecMatchLimitOneValue = kSecMatchLimitOne as NSString
class KeychainManager {
class func setString(value: NSString, forKey: String) {
self.save(serviceIdentifier, key: forKey, data: value)
}
class func stringForKey(key: String) -> …Run Code Online (Sandbox Code Playgroud) 说我有以下代码,在记事本中嘲笑,所以原谅任何小错误:)
//Default page
public ActionResult Index()
{
var musicViewModel
{
Albums = GetTopSellingAlbums(5),
Genres = GetTopGenres(5),
Artists = GetTopArtists(5)
};
return View(musicViewModel);
}
[HttpPost]
public ActionResult Index(MusicViewModel musicViewModel)
{
//For the example, pretend I have a class called musicStoreSubmission in my
//viewmodel which holds a few different fields the user fills out.
if(ModelState.IsValid)
{
//Do some actions based on the user submitting a form
}
//Else, refresh page with errors in Modelstate.
var musicViewModel
{
Albums = GetTopSellingAlbums(5),
Genres = …Run Code Online (Sandbox Code Playgroud) actionresult ×1
asp.net-mvc ×1
code-first ×1
controllers ×1
ctp4 ×1
ios ×1
keychain ×1
swift ×1
testflight ×1
xcode ×1