Foreign keys not recognised - subsonic

when generating an activerecord.cs from mysql using subsonic, some foreign keys are overlooked by the template. it acknowledges the table and columns, just not the relations.
i have checked all the basic things like made sure its the correct db, flushed tables, deleted classes etc.
the db is created using a dump. when i generate from this version everything works correctly. i then add some tables, which relate to existing ones. when i generate again, the new relations are missed by subsonic. the new tables have the same foreign key as existing tables.
ANY ideas will help me at this stage
thanks

solved it. although my connection string was correct(used for table generation), the following line was incorrect(used for foreign key generation) in Settings.ttinclude:
const string DatabaseName = "db";

Related

Creating new tables on the fly using sequelize

This is actually the first time I'm posting something here. The problem I have is driving me crazy since I know such functionality exists elsewhere.
I'm trying to find a way to create new tables on the fly on node js using sequelize without having to restart the database (a DB implemented with SQL).
Moreover, I also need to create new associations between those new table and existing ones.
Why do I need this:
I'm creating a crm and one of the functionalities I want to add is to let users create new types of objects that could have fields referencing to other preexisting ones.
And I can't just restart the whole database everytime a user is creating a new object or fields.
If you guys know how to achieve that or maybe advising me to build the database with another language I'll go for it.
Thanks!

How to use existing data with azure?

https://azure.microsoft.com/en-us/documentation/articles/mobile-services-dotnet-backend-use-existing-sql-database/
I have been following this tutorial but it ends up creating a new table emptying all the data. How do I make it uses existing values inside an existing table?
The tutorial indeed populate example data using Database.SetInitializer(new ExistingInitializer()); but it wont make new DB.
Make sure you have correct connection string Name=MS_TableConnectionString (step 4 in Exploring the existing database model) so it points out to you existing DB
Edit:
First of all, comment out database seeder Database.SetInitializer(new ExistingInitializer()); and to query your existing data use GetAllMobileCustomers in MobileCustomerController or GetAllMobileOrders in MobileOrderController it will give you IQueryable of MobileCustomer of MobileOrder object, use that object as you wish

What is the best way to add tables to Entity Framework 6 Code First to Existing Database?

I'm developing an ASP.NET MVC 4.5 project using EF 6 Code First to an Existing Database. I would like to create some new tables with foreign key relationships to one of the tables in the dbcontext I've created. I've altered and added columns in that original table, creating several migrations. There is real data in that table.
I would prefer to create the new tables in the database, but don't see how EF would generate a model for me. I can code the model myself, but don't see any documentation about how I would add it to the context class generated by EF. And then the migrations would be out of whack.
So I'm thinking that the best thing to do would be to delete all the migrations, delete the context class and drop the migrations table. Then I could start from scratch with an initial migration. Am I missing some gotcha? Is there a better way?
FWIW to others facing this dilemma, I figured it out. First I got rid of all the migrations, following the 100+ up-voted answer here: Reset Entity-Framework Migrations
Second, I created new the tables and constraints I needed in the database.
Third, I created a new entity in my solution and generated model classes from the database. I changed calls from the old entity to the new entity.The generator overwrote the model for the original table, but since I have all the annotations in version control, it is trivial to paste them in.
If I need to, I can enable migrations again.
Hope this helps.

How to use SubSonic SimpleRepository with NON Plural Table Names

I have found out that SubSonic SimpleRepository expectes plural table names however I have started working on a database that doesn't have this and I am unable to change the table names.
Is there a way I can use Subsonic without making database changes?
I have seen one suggestion but I don't fancy that too much.
I'm not tied to using the SimpleRepository I just thought it would be easiest as I need the ability to swap database connections (SQL & Oracle) based on the clients requirements. The schema is the same on both. With SimpleRepository I can just swap out the connection string in the web.config.
You can apply the SubSonicTableNameOverride attribute on your classes you use with Simple Repo and use an arbitrary table name!

How can I obtain the database schema from an existing ActiveRecord.cs file?

I have been given the source code for an existing project that uses SubSonic ORM. My (limited!) understanding is that SubSonic generates code by reverse-engineering the existing database. Unfortunately I don't have the database that was used for this project.
I do have the ActiveRecord.cs file from the last time it was compiled. How could I work out the database schema so I can reproduce the database?
This sounds like SubSonic 3. Here are a couple places to get you started based on me looking through my ActiveRecord.cs file. You might want to create a small database yourself, run SubSonic on it, and see what gets generated in ActiveRecord.cs.
Inside your ActiveRecord.cs file, you'll find one partial class per table. The partial class will inherit from IActiveRecord and will likely be the name of the table.
Inside the class, you'll find a function called "KeyName()" which will return your primary key column name for the table. SubSonic requires a primary key for tables it processes and generates code for.
Look for a region named " Foreign Keys ". If this table has foreign keys, you'll find a property corresponding to each foreign key, something like "public IQueryable OtherTableNames". So this table should have a column named something like "OtherTableNameID"; check the generated partial class for the foreign key table to be sure.
Immediately below the foreign key region, you'll find properties for the non-foreign key columns of this table. You can somewhat guess at the data types of the columns from the property data types (e.g. string might be a char(x) or a varchar(x)).

Resources