asp.net mvc 5 - EntityFramework Exclude Some Fields in Updating and Inserting -


this 1st ever project entity framework , want ignore data columns in insert, update activities. still need bind them when display data on view.

in following picture, can see codes in model , table structure

enter image description here

in sql server, datecreated, set default value of 'getdate()' , should ignored in insert , update statement @ all.

similarly, usercreated , datecreated should excluded in update operation too.

but when tried catch sql scripts sent server, values included in generated sqls , it's causing me error datetime overflow, null value not accepted, etc..

generated sql script in sql profiler

exec sp_executesql n'insert [dbo].[events]([title], [detail], [startdate], [starttime], [endtime], [categoryid], [campus], [location], [datecreated], [usercreated], [datemodified], [usermodified], [state], [isposted])          values (@0, @1, @2, @3, @4, @5, @6, null, @7, @8, null, null, @9, @10)  select [eventid]                 [dbo].[events] @@rowcount > 0 , [eventid] = scope_identity()',         n'@0 varchar(1000),@1 varchar(4000),@2 datetime2(7),@3 time(7),@4 time(7),@5 varchar(10),@6 varchar(100),@7 datetime2(7),@8 varchar(50),@9 tinyint,@10 bit',@0='football',     @1='welcome <strong>football </strong>match',@2='2016-01-29 00:00:00',@3='07:00:00',@4='12:00:00',@5='gig',@6='xxxx',@7='0001-01-01 00:00:00',@8='username',@9=0,@10=0 

insert

use [databasegenerated(databasegeneratedoption.computed)] data annotation on datecreated column use default value generated database.

https://msdn.microsoft.com/en-us/data/jj591583.aspx#databasegenerated

update

entity framework update modified field, don't change value of usercreated , not updated.


Comments

Popular posts from this blog

php - Wordpress website dashboard page or post editor content is not showing but front end data is showing properly -

javascript - Get parameter of GET request -

javascript - Twitter Bootstrap - how to add some more margin between tooltip popup and element -