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

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)).

Related

JOOQ Code generation could take into account composite unique constraints

Jooq - 3.13
We are using Jooq Codegen to generate using the org.jooq.meta.extensions.ddl.DDLDatabase generation strategy.
When I have a table ex: Employee with a unique key constraint on say employee_number (this column is not a primary key) it generates a very useful method fetchOneByEmployeeNumber however I cannot say the same about composite keys.
If there is a composite unique key on (department_id, employee_number) then I'd like a method findOneByDepartmentIdEmployeeNumber(Long departmentId, Long employeeNumber). Is this possible? (Obviously I can roll my own method for this purpose but we have quite a few of these constraints and auto generated methods will be very helpful)
This isn't being done right now for DAOs in jOOQ's code generator. I've created a feature request for this: https://github.com/jOOQ/jOOQ/issues/10597
As a workaround, you can extend jOOQ's JavaGenerator::generateDaoClassFooter method to generate your own, see: https://www.jooq.org/doc/latest/manual/code-generation/codegen-custom-code/

Name the primary key of Container in Cosmbos DB Sql Api different than "id"

I am working on Azure and I have created a database with Cosmos DB SQL API. After creating a container I see that the primary key is always named "id". Is there any way to create a container with PK with name different than "id"?
Every document has a unique id called id. This cannot be altered. If you don't set a value, it is assigned a GUID.
When using methods such as ReadDocument() (or equivalent, based on the SDK) for direct reads instead of queries, a document's id property must be specified.
Now, as far as partitioning goes, you can choose any property you want to use as the partition key.
And if you have additional domain-specific identifiers (maybe a part number), you can always store those in their own properties as well. In this example though, just remember that, while you can query for documents containing a specific part number, you can only do a direct-read via id. If direct reads will be the majority of your read operations, then it's worth considering the use of id to store such a value.
PK = primary key, by the way ;) It's the "main" key for the record, it is not private :)
And no, as far as I know you cannot change the primary key name. It is always "id". Specifically it must be in lowercase, "Id" is not accepted.

Can we add primary key to collection datatypes?

When I tried to retrieve table using contains keyword it prompts "Cannot use CONTAINS relation on non collection column col1" but when I tried to create table using
CREATE TABLE test (id int,address map<text, int>,mail list<text>,phone set<int>,primary key (id,address,mail,phone));
it prompts "Invalid collection type for PRIMARY KEY component phone"
One of the basics in Cassandra is that you can't modify primary keys. Always keep that in mind.
You can't use a collection as primary key unless it is frozen, meaning you can't modify it.
This will work
CREATE TABLE test (id int,address frozen<map<text, int>>,mail frozen<list<text>>,phone frozen<set<int>>,primary key (id,address,mail,phone));;
However, I think you should take a look at this document: http://www.datastax.com/dev/blog/cql-in-2-1
You can put secondary indexes on collections after cql 2.1. You may want to use that functionality.

Default primary key setter and getter generated by Service Builder

I'm working with Liferay. When create an entity, we define one column as the primary key. Then I look at the entity model, I see some methods setPrimaryKey, getPrimaryKey as well as the setter and getter of the column that we defined as the primary key before. What is the difference of these methods? Do we need to use both methods once we add new entity into the table or just one
Assuming that your project is built by many people. Some one designs entity and you only code view page. When you want to get or set primary key of entity but you don't know what column. If don't have setPrimaryKey or getPrimaryKey methods, do you look up in the code to find what column is primary key?

Foreign keys not recognised

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";

Resources