Created
September 10, 2019 03:28
-
-
Save danielplawgo/beda580841d9d335ae7da96ada1aabc8 to your computer and use it in GitHub Desktop.
Respawn - usuwanie danych z bazy
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
DELETE "dbo"."PersonBooks"; | |
DELETE "dbo"."People"; | |
DELETE "dbo"."Books"; | |
DELETE "dbo"."Categories"; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
select | |
fk_schema.name, so_fk.name, | |
pk_schema.name, so_pk.name, | |
sfk.name | |
from | |
sys.foreign_keys sfk | |
inner join sys.objects so_pk on sfk.referenced_object_id = so_pk.object_id | |
inner join sys.schemas pk_schema on so_pk.schema_id = pk_schema.schema_id | |
inner join sys.objects so_fk on sfk.parent_object_id = so_fk.object_id | |
inner join sys.schemas fk_schema on so_fk.schema_id = fk_schema.schema_id | |
where 1=1 AND so_pk.name NOT IN (N'__MigrationHistory') |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class BaseModel | |
{ | |
public BaseModel() | |
{ | |
IsActive = true; | |
} | |
public int Id { get; set; } | |
public bool IsActive { get; set; } | |
public DateTime CreatedDate { get; set; } | |
public string CreatedUser { get; set; } | |
public DateTime UpdatedDate { get; set; } | |
public string UpdatedUser { get; set; } | |
} | |
public class Category : BaseModel | |
{ | |
public string Name { get; set; } | |
} | |
public class Book : BaseModel | |
{ | |
public string Title { get; set; } | |
public int CategoryId { get; set; } | |
public virtual Category Category { get; set; } | |
public virtual ICollection<Person> Authors { get; set; } | |
} | |
public class Person : BaseModel | |
{ | |
public string FirstName { get; set; } | |
public string LastName { get; set; } | |
public virtual ICollection<Book> Books { get; set; } | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Program | |
{ | |
private static Checkpoint _checkpoint = new Checkpoint | |
{ | |
TablesToIgnore = new[] | |
{ | |
"__MigrationHistory" | |
} | |
}; | |
static void Main(string[] args) | |
{ | |
SeedData(); | |
_checkpoint.Reset(ConfigurationManager.ConnectionStrings["DefaultConnection"].ConnectionString).Wait(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment