EF generic repository c# get values direct from database code example
Example 1: create new object from generic c#
return (T)Activator.CreateInstance(typeof(T), new object[] { param });
Example 2: Core Data Quickest way to delete all instances of an entity swift
public func clearDatabase() {
guard let url = persistentContainer.persistentStoreDescriptions.first?.url else { return }
let persistentStoreCoordinator = persistentContainer.persistentStoreCoordinator
do {
try persistentStoreCoordinator.destroyPersistentStore(at:url, ofType: NSSQLiteStoreType, options: nil)
try persistentStoreCoordinator.addPersistentStore(ofType: NSSQLiteStoreType, configurationName: nil, at: url, options: nil)
} catch let error {
print("Attempted to clear persistent store: " + error.localizedDescription)
}
}
}