primary-key

Database Primary Key C# mapping - String or int

ぃ、小莉子 提交于 2019-12-01 08:56:09
问题 In the Northwind Starters Kit, Primary keys from database are mapped to Strings in C#. Is this good practice? And if so, why? thx, Lieven Cardoen ps: Sorry for the maybe wrong question... In Northwind Starters Kit some tables have a auto-incremental primary key with datatype int and others have a non auto-incremental primary key with datatype nchar(5). Why is this? Well, apparently some primary keys are just codes (nchar(5) format). So sorry to have used your time. I thought that a datatype

Symfony/Doctrine: DateTime as primary key

若如初见. 提交于 2019-12-01 07:09:04
I am trying to make an Entity using a date as a primary key. The problem is that Symfony can't convert the DateTime I'm using into a string to introduce it in the IdentityMap. I get the following error during the persist of the entity: Catchable Fatal Error: Object of class DateTime could not be converted to string in.. I'm using this code in the entity : /** * @ORM\Id * @ORM\Column(type="datetime") */ protected $date; The error appears in the entity repository : $em = $this->getEntityManager(); $currentData = new CurrentData(); ... $currentData->setDate(new \DateTime($dateStr)); ... $em-

How to get generated keys by executeBatch without ArrayIndexOutOfBoundsException?

我们两清 提交于 2019-12-01 06:34:53
问题 The following method I want to INSERT several records simultaneously. public void insert() { try { this.connection.setAutoCommit(false); PreparedStatement ps = this.connection.prepareStatement( "INSERT INTO COMPANY (NAME,Address) Values (?,?)", new String[]{"ID"}); ps.setString(1, "X01"); ps.setString(2, "Address1"); ps.addBatch(); ps.setString(1, "Y01"); ps.setString(2, "Address2"); ps.addBatch(); //EXCEPTION OCCURS HERE int[] numUpdates = ps.executeBatch(); for (int i = 0; i < numUpdates

Symfony/Doctrine: DateTime as primary key

戏子无情 提交于 2019-12-01 05:16:54
问题 I am trying to make an Entity using a date as a primary key. The problem is that Symfony can't convert the DateTime I'm using into a string to introduce it in the IdentityMap. I get the following error during the persist of the entity: Catchable Fatal Error: Object of class DateTime could not be converted to string in.. I'm using this code in the entity : /** * @ORM\Id * @ORM\Column(type="datetime") */ protected $date; The error appears in the entity repository : $em = $this->getEntityManager

Reordering Identity primary key in sql server

微笑、不失礼 提交于 2019-12-01 04:44:21
Yes i am very well aware the consequences. But i just want to reorder them. Start from 1 to end. How do I go about reordering the keys using a single query ? It is clustered primary key index Reordering like First record Id 1 second record Id 2 The primary key is Int gopinath s Drop PK constraint Drop Identity column Re-create Identity Column Re-Create PK USE Test go if(object_id('IdentityTest') Is not null) drop table IdentityTest create table IdentityTest ( Id int identity not null, Name varchar(5), constraint pk primary key (Id) ) set identity_insert dbo.IdentityTest ON insert into dbo

Entity Framework 4.1 Database First does not add a primary key to the DbContext T4 generated class

强颜欢笑 提交于 2019-12-01 04:12:36
I am just getting started with Entity Framework 4.1, trying out the "database first" mode. When EF generates a Model class with the "ADO.Net DbContext Generator," shouldn't it identify the primary key for the class with a [Key] attribute? Without this, it appears incompatible with the T4 MVCScaffolding. Here are the details: Using the Entity Data Model Designer GUI, I have added a simple "country" table to the model from my existing database. The GUI correctly identifies a single integer identity key field named "PK" as my primary key. (Alas! I'm a new user so I can't add a screenshot. I've

Auto increment a non-primary key field in Ruby on Rails

∥☆過路亽.° 提交于 2019-12-01 03:55:21
In a RoR migration, how do I auto increment a non-primary-key field? I'd like to do this in the db definition, and not in the model. user386660 You need to execute an SQL statement. statement = "ALTER TABLE `users` CHANGE `id` `id` SMALLINT( 5 ) UNSIGNED NOT NULL AUTO_INCREMENT" ActiveRecord::Base.connection.execute(statement) you can entry manually in your migration Note this is just an example. The final SQL statement syntax depends on the database. 来源: https://stackoverflow.com/questions/3220473/auto-increment-a-non-primary-key-field-in-ruby-on-rails

renumber primary key

匆匆过客 提交于 2019-12-01 03:55:13
How would I reset the primary key counter on a sql table and update each row with a new primary key? I would add another column to the table first, populate that with the new PK. Then I'd use update statements to update the new fk fields in all related tables. Then you can drop the old PK and old fk fields. EDIT: Yes, as Ian says you will have to drop and then recreate all foreign key constraints. Zachary Yates Not sure which DBMS you're using but if it happens to be SQL Server: SET IDENTITY_INSERT [MyTable] ON allows you to update/insert the primary key column. Then when you are done updating

Entity Framework foreign keys to non-primary key fields

眉间皱痕 提交于 2019-12-01 03:30:18
Is it possible for Entity Framework 4.0 to have an association/navigation property based off of a foreign key to a non-primary key field (it has a unique constraint). No because EF don't understand unique constraint yet and relations in EF must follow same rules as relations in database. Without unique principal relation cannot exist and the only way to get unique principal in EF is using primary key. 来源: https://stackoverflow.com/questions/9217448/entity-framework-foreign-keys-to-non-primary-key-fields

Entity Framework 4.1 Database First does not add a primary key to the DbContext T4 generated class

倾然丶 夕夏残阳落幕 提交于 2019-12-01 01:25:56
问题 I am just getting started with Entity Framework 4.1, trying out the "database first" mode. When EF generates a Model class with the "ADO.Net DbContext Generator," shouldn't it identify the primary key for the class with a [Key] attribute? Without this, it appears incompatible with the T4 MVCScaffolding. Here are the details: Using the Entity Data Model Designer GUI, I have added a simple "country" table to the model from my existing database. The GUI correctly identifies a single integer