Print Page | Close Window

A column that should not be persisted

Printed From: IdeaBlade
Category: DevForce
Forum Name: DevForce Classic
Forum Discription: For .NET 2.0
URL: http://www.ideablade.com/forum/forum_posts.asp?TID=2019
Printed Date: 23-Apr-2025 at 4:55pm


Topic: A column that should not be persisted
Posted By: agrogers
Subject: A column that should not be persisted
Date Posted: 27-Jul-2010 at 10:56pm
Hi

We have been looking at the 'Source Access Type' (pg 74) property.  We have a 'Tag' field in many tables which we use to track selected records.  I understand the SourceAccessType property will stop modified fields from being written back to the database.  This is exactly what we need.

However, the documentation does not state that changing this property leaves dirty state of the record unchanged.  We dont want to write back records to the DB that have simply had their Tag property changed.  I would guess that it would not since we are not writing the property back.  But I just wanted to confirm that.

Thanks
Andrew



Replies:
Posted By: smi-mark
Date Posted: 28-Jul-2010 at 2:13pm
Why does it have to be a database column? Simply add a property to your object.

public string Tag
{
    get;
    set;
}


Posted By: davidklitzke
Date Posted: 28-Jul-2010 at 4:05pm

A  SourceAccessType of ReadOnly will stop DevForce from writing that property to the database on an insert or update.  The record is still considered modified though, so when PM.SaveChanges() is called the entity will be part of the save list.  If that’s not wanted then these entities can be stripped out of the list passed to SaveChanges, or they can be removed from the list via the PM.Saving event.



Posted By: agrogers
Date Posted: 28-Jul-2010 at 5:09pm
Originally posted by smi-mark

Why does it have to be a database column? Simply add a property to your object.

public string Tag
{
    get;
    set;
}

I think this is the best way for us to move forward on this one.   Will see how it goes.  Thanks.


Posted By: agrogers
Date Posted: 28-Jul-2010 at 5:51pm
Originally posted by davidklitzke

A  SourceAccessType of ReadOnly will stop DevForce from writing that property to the database on an insert or update.  The record is still considered modified though, ...



Thanks for clarifying this David.  I am not sure that the extra work to exclude those records that are not dirty is worth our while at present.  Will need to investigate it further. 

Our scenario means that the Tag property of 1000s of records could be touched (and touched often) with none of those records every actually being modified.  With SourceAccessType of the Tag column set to readonly we would be writing back to the DB 1000s of identical records ... not really what we want to do.

Is there a reason that a change to a column that is never persisted stills triggers a persist to the DB?  That doesnt seem right to me.

Thanks
Andrew



Print Page | Close Window