FK Issue, Order of creation

I need to create about 500 Tables with complex FK. I created the C# classes but the issue is these tables have to be created in a given order (Parent Table needed to be created before child table). Going through 500+ classes and ordering them is going to be time consuming, any other options. ?

You can automate ordering. Load all POCO classes via reflection and check recursively if their member has [Reference] attribute. Then get the the type from this attribute and call the check method again. When you meet the type without [Reference] attribute put it to the List<Type> and return. When this algorithm ends you’ll get list of types which are ordered in the way when parent tables go first and child tables go only after parents.

Good point. Will do.

This is bit more complecated than I thought as I need to develop a proper depdency managment. In short term I am creating the tables with OrmLiteConfig.SkipForeignKeys = true; then running code like

             var sql = "ALTER TABLE[dbo].[FirstChild] DROP CONSTRAINT[FK_TempSales_SalesReason]";

Is this the only way to create / drop FK ?