Skip to content

Instantly share code, notes, and snippets.

@danielplawgo
Created September 10, 2019 03:28
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save danielplawgo/beda580841d9d335ae7da96ada1aabc8 to your computer and use it in GitHub Desktop.
Save danielplawgo/beda580841d9d335ae7da96ada1aabc8 to your computer and use it in GitHub Desktop.
Respawn - usuwanie danych z bazy
DELETE "dbo"."PersonBooks";
DELETE "dbo"."People";
DELETE "dbo"."Books";
DELETE "dbo"."Categories";
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')
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; }
}
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