Hi i am using Entity framework 4.3.
I had a table "Notes" in which NoteId is primary key(data type is int). I generated value for NoteId like this by using stored procedure..
notes.NoteId = (int)dbContext.GeneratePrimaryKey("Notes");
When i am inserting data to the table "Notes" it raises that null value cannot be inserted into noteid. But the noteid is generated.
Can any one please help me to solve the issue....
I guess your mapping expects that the primary key is autogenerated in the database. In such case your value will not be used. Verify that in your EDMX the NoteId property has StoreGeneratedPattern set to None.
Related
I am new to SAP PowerDesigner I am trying to created tables and link them together to get the DB model and I am having difficulties on enabling Auto increment for the primary Key column of tables. Can someone please guide me
I have looked online and there was mentioning of check marking something called as Identity. But I do not see that option on Column properties.Image2
Image1
Which version of Oracle are you using?
Oracle 12+ supports identity columns. In PowerDesigner, the Identityoption is available in the Oracle tab on the Column, when the DBMS for the Physical Data Model is ORACLE Version 12c.
create table CONTACTS (
ID int
generated always as identity ( start with 1 nocycle noorder) not null,
NAME varchar(100) not null,
constraint PK_CONTACTS primary key (ID)
);
For previous versions of Oracle, the autoincrement was implemented with sequence, and triggers. See this page of PowerDesigner online documentation for example.
I'm trying to understand Room database library. I am struck with a scenario where two tables are linked via #ForeignKey constraint. What I need is, when the parent row is deleted, all the child columns in the child table should be set to NULL or some default value. But when I tried to use
onDelete=SET_NULL or SET_DEFAULT with #ForeignKey
I get the following error:
android.database.sqlite.SQLiteConstraintException: NOT NULL constraint
failed: Log.tagId
From the error I can see that the child column has been set as NOT NULL during the table definition, can someone say how to change it to be NULLABLE since room creates the tables for us? Also, it is ok if we can set a standard default value on the columns. If so, how to set the default value of columns? I think there should be some way else the constants SET_NULL or SET_DEFAULT has no meaning and purpose.
Thanks in advance!
I've created a simple table in Oracle 12c like so:
CREATE TABLE TEST
(
ID NUMBER GENERATED ALWAYS AS IDENTITY,
TEXT VARCHAR2(2000 CHAR),
CONSTRAINT ID_PK PRIMARY KEY (ID)
);
Then I linked it in MS Access using ODBC driver. The problem is that when I input value into TEXT and click away both ID and TEXT show #Deleted. My value gets recorded in the database but I have to requery in MS Access in order to see it.
I also noticed that if I change the datatype of TEXT field to NUMBER, it works fine. After saving the record in MS Access both auto generated ID and value in TEXT field are there. I don't have to requery anything.
This happens only when inserting. Updating works just fine.
Please advise.
So, it would appear you already found the solution, but this is more of an explanation as to why it works that way. Simply speaking, if the base-table uses non-integer values as primary keys, Access rounds these integers to the nearest whole number and then (since it was not a numeric value) Access can no longer find the applicable records. So, changing the data type from TEXT to INTEGER in the table structure would give you your desired result.
Alternatively, if you're using a query to run through these, if you cannot change the keys in the Oracle table then altering the Access query type to a snapshot (in the query properties) will also bypass this problem. But from the sounds of it, this is not how you are utilizing the data.
In my case, the Oracle ODBC driver (using the rather old version 11.02.00.01 that otherwise works ok and Microsoft Access 2016 32Bit) seems to use the unique indices and not the primary key constraint for determining the primary key.
I had a field with NUMBER(11) as PK with an unique index, then added a VARCHAR2 field with another unique index. The name of the index of the VARCHAR2 field was alphabetically before that of the NUMBER field.
Now, the linked table in Microsoft Access showed the VARCHAR2 field as primary key and I had the problem with '#Deleted' appearing after entering & saving a record as you describe.
After renaming the unique index on the NUMBER field in Oracle to be alphabetically before that of the VARCHAR2 field and re-linking the table in Microsoft Acces, the NUMBER field was the primary key again in Microsoft Access and the '#Deleted' problem was solved.
I've added a new table definition to a project folder and then created a primary key, however when I click on the 'columns' to create a key component its telling me no mandatory columns are in the Table Definition - create one or more mandatory columns. I've gone back to table definitions but I can't see how I do this and then assign columns to the Primary key?
Any help appreciated!!
Consider the following tables:
create table master
( nr number(10,0) identity primary key
lastmodified date
scn number(12,0) -- update from sequence with every update
)
create table details
( nr number(10,0) primary key
linenum number(3,0) primary key
<more details>
scn number(12,0) -- update from sequence with every update
)
Table Details has a foreign key from column nr to column nr. Both tables are mapped to entities with the primary database keys as entity keys. There is a one-to-many relation between Master and Detail.
When I add a master with a single detail to the EF context and call SaveChanges, the nr field in the master is determined by a trigger in the database, returned to EF, written into the details.nr property and saved in the details table. Well done, EF!
But when I try to update one of the details fields in the details entity adn call SaveChanges, I get the error "The property 'Nr' is part of the object's key information and cannot be modified." Apparently EF tries to update the Nr field from the related Master. Which is not modified, of course.
What is the best way to work around this limitation? Adding a new entity key field and changing the primary key columns is not an option.
Disclaimer: I wrote the code by hand to focus on the issue, it may not compile but I hope you get the point.
Update: I think (hope...) that the problem is solved. If I set the SCN field in the Detail entity to both ConcurrencyMode=Fixed AND StoreGeneratedPattern=Computed, the error message about the Nr field appears. If I set the SCN fields to ConcurrencyMode=Fixed and StoreGeneratedPattern=None, the SaveChanges returns without errors.