Last post May 06, 2019 03:56 PM by PatriceSc
May 06, 2019 09:39 AM|aabedeni056|LINK
hello. i have fields( id,radif,moteghazi ,...... in my table . )
i want automaticly value "id" put in field "radif" . i show "radif " in my views with values radif .
thank you .
May 06, 2019 09:47 AM|PatriceSc|LINK
Not 100% clear. You are using SQL Server? My first thought would be to try a trigger (id is an identity value generated by the database ? I never tried a trigger that does a copy of a db generated value)
What is the purpose of having two columns having the same value ? (for example you could have a not mapped property that would just expose the value of the id column ?)
It's always easier to suggest Something when knowing the final goal...
May 06, 2019 09:55 AM|aabedeni056|LINK
thank your answer .
i have 2 field" id , radif"(int) . i want to increase id every time ,it value put in property radif in my table .
i use asp.net mvc , sql . i dont know how to do it in my controller , display "radif " in my view.
May 06, 2019 03:56 PM|PatriceSc|LINK
I still don't get what you want to do with "radif".
With SQL Server you can have a column which is automatically incremented using :
CREATE TABLE t(id INT IDENTITY NOT NULL CONSTRAINT pk_t PRIMARY KEY, data VARCHAr(10))
INSERT INTO t VALUES('A'),('B'),('C')
SELECT * fROM t
If you want to copy the id value to radif it seems something like below works :
CREATE TABLE t(id INT IDENTITY NOT NULL CONSTRAINT pk_t PRIMARY KEY,data VARCHAR(10),radif INT NOT NULL)
CREATE TRIGGER t_insert ON t FOR INSERT AS
UPDATE t SET t.radif=inserted.id
from t join inserted on t.id=inserted.id
INSERT INTO t(data,radif) VALUES('A',0),('B',0),('C',0)
SELECT * FROM t