I have a simple table with columns ID, REGDATE and EVENT_NAME. I've set SYSDATE as default value for the REGDATE column. If I insert a record right from SQL Developer current date is written to the REGDATE column. But if I insert a record with Entity Framework REGDATE column has NULL. Don't database defaults work when using Entity Framwork? What do I have to do?
One way that you can do it is by having a constructor in your class to set that default automatically whenever you instantiate a new object of that type. This is similar to Ladislav's answer to this SO question.
yo can set that properties,StoreGeneratedpattern to Computed and then EF won't update it, but then neither can you. This method will solve your Db default on the column.
Related
I'm pretty new to APEX and programming as a whole, so bear with me. I have a table I created using dynamic PL/SQL and have a TO and FROM datepicker to set the range of rows to select. It is functioning great so far but I'm having a problem with the defaults for both datepickers. I've set the FROM datepicker to default to one year in the past and the TO datepicker is set to the current date. I've set them both using a SQL expression in the default field. Whenever you change the date and refresh, the table selects the correct rows. BUT if you want to remove the dates in both pickers so that you can see every row in the table, the null values are being reset to the default values after refreshing the page. I feel like there's probably a very simple way to fix this, but I'm at a loss. Any help with this would be greatly appreciated!
An item gets its value from session state; if it doesn't exist, then from source; if it doesn't exist (and the item is still NULL), then default value is used.
Therefore, what you did is just the opposite of what you want - if everything else is NULL, default value is used.
What to do? Don't set default value for the item - use it directly in report's WHERE clause. Something like this:
select whatever
from your_table
where some_conditions
and date_column between nvl(:P1_DATE_FROM, add_months(trunc(sysdate), -12))
and nvl(:P1_DATE_TO , trunc(sysdate))
So:
if P1_DATE_FROM and/or P1_DATE_TO are set, these values will be used
if they are NULL, they will be set to previous year and today
Of course, you'd remove both item's default values.
I'm using EF Core to connect to an Oracle11g database (using the Oracle.EntityFrameworkCore v2.19.90 provider). It's a code first scenario, the tables are created successfully and everything is as expected.
The problem is, when I try to insert something into the database, for example:
_context.Roles.Add(new ApplicationRole()
{
Name = "FOO",
DisplayName = "Foo"
});
_context.SaveChanges();
I get an error:
OracleException: ORA-01400: cannot insert NULL into ("SCHEMA"."AppRole"."Id")
The column Id is indeed non-nullable. When I use the SQL Server provider, everything is fine, the SQL Server automatically chooses an id for my entity.
Is there any way to get Oracle to set an Id for me? Or could it be done in another way?
I don't want to use Oracle triggers and the solution should be full code first.
As you're on Oracle 11g, then you have to use a trigger along with a sequence which will populate ID column in the background.
Another option is to, obviously, provide ID value during insert.
If you were on 12c or above, you could have used identity column. As you're not, your options are listed above.
One option may be usage of SEQUENCE and default value:
CREATE TABLE AppRole(
Id INT NOT NULL,
Name VARCHAR2(100),
DisplayName VARCHAR2(100)
);
CREATE SEQUENCE seq;
ALTER TABLE AppRole MODIFY Id DEFAULT seq.NEXTVAL;
INSERT INTO AppRole(Name, DisplayName) VALUES ('Foo','Foo');
db<>fiddle demo
Default with sequence is supported from Oracle 12c.
There should exist syntax in EntityFramework core that allow to do the following without relying on triggers(raw SQL query as last resort):
INSERT INTO AppRole(Id, Name, DisplayName) VALUES (seq.NextVal, 'Foo','Foo');
Sequences
Basic usage
You can set up a sequence in the model, and then use it to generate
values for properties: C#
protected override void OnModelCreating(ModelBuilder modelBuilder)
{
modelBuilder.HasSequence<int>("OrderNumbers");
modelBuilder.Entity<Order>()
.Property(o => o.OrderNo)
.HasDefaultValueSql("NEXT VALUE FOR shared.OrderNumbers");
}
Note that the specific SQL used to generate a value from a sequence is
database-specific; the above example works on SQL Server but will fail
on other databases. Consult your specific database's documentation for
more information.
Oracle syntax is sequence_name.NEXTVAL.
I have a Form Applet and it has the Field SERIAL_NUM From the S_CASE Table , but whan i wont to insert a new record i get the Field Empty , how can i ganarate a SERIAL_NUM to insert to the table like the ones in the S_CASE table , is there and Predefult expretion that dose it ?
Best Regards
In the Siebel Object Type Business Component Field
has attribute named
Predefault Value
you can provide Siebel valid expression to populate value when creating new record using expression
Field: 'Id'
or
Expr: 'RowIdToRowIdNum ([Id])'.
Alternatively you can also write Server side script on
Siebel Object Type Business Component
in the method
BusComp_PreNewRecord
to populate customized value when creating new record.
Alternatively you can also use
Database Trigger
which can also populate customized value to columns and will be available in Business Component Field value.
I need to update the column values to table in phpfox forum module posting new thread general type. I have found the table name in coding (query) and added values to column but I am not getting col values. Can anybody help?
my db name : munpal
table name : forum_post
colmun name : mark value (here I need to add my values )
Open module\forum\include\service\thread\process.class.php and look add function in that.
This function is called when a thread is added you can modify the function according to your need. May this helps you
Using Entity Framework and Oracle DB, I would like to
insert into tablename (datetimefield, numericfield) VALUES (sysdate, 545)
How to do that without using SQL code directly?
Its not possible to set it directly using the entity framework as part of the update. For inserts you coud set a default value on the table and leave it null. You could also expose an sp that updates the date to the entity framework, and call it, but that could cause many round trips.
You could also use a trigger.
If you work with dotConnect for Oracle, you can use this solution.
Devart Team