Create domain partition with Dapper FastCrud ModelGenerator - dapper

Our Sql Server database has multiple schemas/owners. Some of the table names are identical without the schema so when configuring the Model Generator I would like to be able to either filter by schema or append the schema name to the table so there is no conflict. I have tried filtering by table prefix but that only seems to work on the table name.
Schema1.Companies
Schema2.Companies
I would like the Model Generator to produce either this
namespace models
[Table("Schema1Companies")]
[Table("Schema2Companies")]
or this
namespace models.Schema1
[Table("Companies")]
namespace models.Schema2
[Table("Companies")]
https://github.com/MoonStorm/Dapper.FastCRUD/wiki/Entity-registration

Digging around the code a little I found the SchemaName variable. So I can create a ModelGeneratorConfig file for each schema with it's own namespace.

Related

Composite Projects - handling additional columns

From this post....
http://blogs.msdn.com/b/ssdt/archive/2012/06/26/composite-projects-and-schema-compare.aspx
...it seems that (Same) Database References are a way to share common parts of a database.
If a specific database needs additional columns on a table from a (Same) Database Reference is there any way of handling that?
I was hoping you might be able to override the definition of a table from a Database Reference simply by re-declaring the table in the referencing Database Project.
e.g. if you had a Employee table in a Common Database project, a definition for Employee table in a Client Database referencing Common Database would override the definition in the Common project. Instead when you go to deploy the porject you get the error...
SQL71508: The model already has an element that has the same name dbo.Employee.
EDIT:
Anticipating the feedback below, the resolution I've made is to not use database references for the existing client databases. Instead I've created a structure as follows....
+OurCompanyDatabases
+Common
Common.sqlproj
+dbo...
+ClientA
+dbo....
+ClientB
+dbo....
ClientA.sqlproj
ClientB.sqlproj
So I've got multiple sqlproj files within the same folder and I include and exclude files from the projects as required.
So for example ClientA's Sales table has a ClientARewardsID column added I exclude the Sales table within the /OurCompanyDatabases/Common/dbo folder and create add a new Sales table within the /OurCompanyDatabases/ClientA/dbo folder.
This way Client A and Client B can retain the full use of SSDT update and deployment, whilst minimizing the duplication of sql scripts. I'm hoping this will reduce the cost of maintenance on the sites.
Going forward I will use database references and additional columns will be added in new tables with a foreign 1:1 foreign key relationship with the Common table.
No it doesn't support an inheritance type model and you can only really share complete objects so in your case you would have it structured like:
proj a - TableA
references - proj shared
proj b - TableA
references - proj shared
proj shared - TableXYZ
Then you can have two different definitions of TableA but still share all of the objects that are the same.
There is another option you could not include the table definition in SSDT or include one or the other and then handle any changes and the deployment yourself in post deploy scripts and use my filter (http://agilesqlclub.codeplex.com/) to stop ssdt deploying any changes to your table but this sort of invalidates one of the main reasons for using ssdt (merge type deployments for free).
ed
It's much safer and better practise to add a new table for the extra columns, and make its primary key a foreign key to the table it extends.

TPT entities derived from TPH base classes in Entity Framework 6?

I have a project that is using EF6 Database first mapped to a SQL database. This is all new so I control the EF model as well as the database schema.
I currently have a table that I'll call Vehicle for simplicity. I use a discriminator column to get subclass Entities Car and Truck. This all works fine.
Now I need to do a 'soft delete' and move any deleted vehicles to a VehicleHistory table. (After trying this w/ EF i will probably use a SQL transaction). This needs to be reviewable so I need this history table mapped as well, but I would like to keep it within the inheritance hierarchy so its easily reused in other classes.
My idea was to create 'vehiclecurrent' and 'vehiclehistory' tables with FK's to Vehicle for shared columns. i would then use TPT in EF to get 'carcurrent','carhistory', ect... derived from my TPH classes(so e.g. carhistory->car->vehicle). This is not working and I get Error 3034: "Entities w/ different keys are mapped to the same row"
So my question is basically how can I pull this off? Will this approach work and how, or is there another way to accomplish this? Thanks!

Many-to-Many relationship in Zend 2 Framework

I use the Zend 2 Framework to build my web application. I implemented my database table models by this tutorial: http://framework.zend.com/manual/2.1/en/user-guide/database-and-models.html
I have a many-to-many relationship between two models in my database. To get data from them I googled and found this link: http://mattmccormick.ca/2010/04/24/how-to-easily-create-models-and-table-relationships-in-zend-framework/
The problem is that all the table models extends from Zend_Db_Table_Abstract in the example. I don't know how to get data from the models.
I have a table containing votings, every voting has a unique hash id. Every voting also has tags. Therefore I defined a table tags with all the tags available and a voting_tag_map where all many-to-many relationships are mapped.
What I have tried so far is the following, that's code from my VotingTable class:
public function getTagsByVoting($votingHash){
$select = $this->tableGateway->getSql()->select();
$select->from(array('v' => 'voting'))
->join('voting_tag_map', 'v.voting_id=voting_tag_map.voting_id')
->join('tags', 'voting_tag_map.tag_id=tags.tag_id');
$resultSet = $this->tableGateway->selectWith($select);
return $resultSet;
}
It says then:
Since this object was created with a table and/or schema in the constructor, it is read only.
Thats because of the from() method. If I delete the from() method, it says:
Statement could not be executed
Can anyone help me please?
Since this object was created with a table and/or schema in the constructor, it is read only.
This error is because you are trying to set the table name in the from clause, but it's already been set in the contructor of the TableGateway, and you can't change it once set.
If you really need to do this then you can extens AbstractTableGateway yourself then you won't have to add a string tablename to the contructor, but you don't really need to use an alias on your main table...
The SQL error you get when you comment out the from() method will be due to your referencing the votes table as it's alias 'v' in your join, when you are not using the alias v, try changing it to 'voting.XXX' from 'v.XXX'

Oracle 11g: How to override default schema tables with test tables for my test user

I know this can be done, because I've seen it at my last workplace, but I don't know how to replicate!
Basically, there is a MASTER user who has write privileges for all our tables. In our application's DB adapter connection settings, we use DEFAULT_SCHEMA: MASTER
I have created a new test user for myself (on the same database as the master user, not using a database link) so that I can freely create test data without messing with real data. Then copied a table for my test user so that I can freely manipulate data: create table SIMMBOT.real_data_table as select * from MASTER.real_data_table
The problem is that I don't know how to set up the connection so that Oracle knows to override MASTER.real_data_table with my own SIMMBOT.real_data_table. I have a hunch that you can't actually do that in the connection settings... so starting from square one, what would I have to do to set up test tables like this? Something like a shared schema?
If your code is using fully qualified table names (i.e. MASTER.real_data_table or SIMMBOT.real_data_table) then there is no way from a configuration standpoint to change what object is being referred to.
Assuming, however, that your code is not using a fully qualified table name-- if it is just selecting from real_data_table, then Oracle will first look for an object in the current schema with that name then look for a public synonym with that name.
If you connect as MASTER, you can change the current schema
ALTER SESSION SET current_schema = SIMMBOT
Once you've done that, all unqualified references to a table name will resolve to tables in the SIMMBOT schema. Note that the MASTER user would need to be granted appropriate access on the objects in the SIMMBOT schema separately-- setting the current schema only affects name resolution, not privileges. The SIMMBOT schema would also need to have every table that the code wants to reference-- there is no way to specify a hierarchy for resolving unqualified names. You can't tell Oracle to first resolve unqualified names in the SIMMBOT schema and then the MASTER schema.
An alternative would be to create synonyms for each table and manipulate the synonyms to reference your table for some or all users. If your application logged in as a third user that did not own any objects-- APP_USER for example-- you could create either private synonyms in the APP_USER schema that pointed to different objects in different schemas--
CREATE SYNONYM app_user.real_data_table FOR simmbot.real_data_table;
CREATE SYNONYM app_user.some_other_table FOR master.some_other_table;
or you could create public synonyms that would apply to all users (other than those that owned the objects)
CREATE PUBLIC SYNONYM real_data_table FOR simmbot.real_data_table;
CREATE PUBLIC SYNONYM some_other_table FOR master.some_other_table;

Entity Framework Foreign Key Mapped to Same Table

This is not a duplicate of this post although the title is very similar. I am using EF4 with MSSQL Express 2008 R2 on VS2010.
A simplified version of my schema is as follows:
Table [Team]:
Id (PK)
Member1
Member2
Table [Person]:
Id (PK)
FirstName
[Team].Member1 and [Team].Member2 are foreign keys pointing to [Person].Id.
When generating the .edmx via VS2010, the navigation properties under [Team] become "Person" and "Person1" despite giving distinct names to the FKs inside SQLServer.
Is it possible to force the .edmx generator to recognize my FK names in SQL Server? I'd like these names to be Member1Person and Member2Person, for example, so I don't have to manually rename them by hand. If not, what is the preferred way to redesign the tables/FKs to bypass this altogether? Thank you.
I have had a similar issue but I believe the answer to the question is you simply have to rename the Navagation property to what you want. The Entity Framwork designer will always keep you changes to the property names on the Conceptual side of things.

Resources