Does current version of SubSonic support PrimaryKey (Int) which is not Autoincrement?
How?
PS: If I don't use SimpleRepository() I can save new record with assigned Id so more or less I can go on, thz.
Without knowing exactly what you mean, I can tell you this much: SubSonic ActiveRecord does support such keys, you just need to remember to set them manually when creating new records.
Related
With Entity Framework it is possible to enable migrations and create migration steps. But is there an intermediate way where it is possible to change the models, and take care of database schema changes yourself? I don't want to drop the database, because there are future production schenario's.
Now - without enable migrations - I use a code first, and when I create another property in a DbSet - lets assume for example in table 'ExistingTable' int NewField {get; set;}
And when in SQL I update my schema with
Alter table ExistingTable add column NewField int not null
the database knows existence of the new field, the Entity Framework / C# knows the property, but when running, there is some hidden check that still want's to drop my database because of the model change.
Question: can I overwrite a certain setting, in such a way that intial 'Code First' can be transformed to database first?
Removing the __MigrationHistory table from the database (Azure) did work fine for me. I made my (simple) database changes myself and published the code. It all runs fine. There is an alternative see EF Code First Migrations Deployment to an Azure Cloud Service. For a simple one-way patch (and no change history needed) removing the __MigrationHistory works fine.
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!
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";
I need to generate a table without primary key. Its absolutely neccessary that the table dosen't have primary key. Please help.
It is absolutely necessary for the SubSonic that table contains primary key:)
The following is quoted from the SubSonic docs on conventions:
Primary Keys
If you want to use SubSonic to access your table, you need to have a Primary Key defined for your table. This is good practice in every case and we need it to do certain things with your table. If you don't have a Primary Key defined, your class won't be generated.
If you don't believe us, or if you think this is a silly convention - SubSonic isn't for you.
Is there any reason you cannot use something like sequences?
class Something {
private static final SEQUENCE seq = getDBsequence()
#id
private final long id = seq.newNumber();
private final String whateverData;
}
EDIT:The way I wrote this was kinda dumb because once you reboot the app. you'll get duplicate keys.. You should use a sequence provided by the DB. Sorry about that.
as Adam pointed out this isn't possible. To be honest I can't think of a situation (outside OLAP) where you can't have a PK. Or perhaps you're stuck in a legacy situation - I can dig that.
What you can do to get around it is, as you pointed out, use our querier tools and then you can send the results ToList<>. Updates should work the same way - not sure about inserts though.
I have a data model that includes common columns like addedBy, editedby (user), addedDate, editedDate.
Is there a setting I can use in SubSonic 2.1 that will automatically update these fields appropriately instead of having to explicitly specify in every update?
Check out http://subsonicproject.com/setup/subsonic-conventions/. SubSonic uses a convention-based approach when it comes to audit columns. If you can change your column names to CreatedBy, ModifiedBy, CreatedOn, and ModifiedOn respectively, then they will be updated automatically. I don't think there's a way to change what those names can be without making changes to the SubSonic source code.