views:

379

answers:

5

Hello guys

here is what i am doing, and not working for me.

I have a DAL generated with SubSonic 3 ActiveRecord template, i have a service layer (business layer if you well) that have mixture of facade and some validation.

say i have a method on the Service layer like public void UpdateClient(Client client); in my GUI i create a Client object fill it with some data with ID and pass it to the service method and this never worked, the dirty columns collection (that track which columns are altered in order to use more efficant update statment) is alwayes empty.

if i tried to get the object from database inside my GUI then pass it to the service method it's not working either.

the only scenario i find working is if i query the object from the database and call Update() on the same context all inside my GUI and this defeats the whole service layer i've created.

however for insert and delete everything working fine, i wonder if this have to do something with object tracking but what i know is SubSonic don't do that.

please advice. thanks. Adel.

A: 

I am having the same issue with DataGrid Update and ObjectDataSource in webfrom.

Shuaib
A: 

I have ASP.NET Web Forms as my GUI.

Adel
A: 

I am having basically the exact same issue but with 2.2....

jonezy
+1  A: 

It seems to be a feature and not a bug. Subsonic will only mark a column as dirty if the object is loaded from DB. So you can't really save and object, add changes to its properties and then save it again. Go figure.

bool _MyProp;
public bool MyProp
{
    get { return _MyProp; }
    set
    {
        if(_MyProp!=value){
            _MyProp=value;
            var col=tbl.Columns.SingleOrDefault(x=>x.Name=="MyProp");
            if(col!=null){
                if(!_dirtyColumns.Any(x=>x.Name==col.Name) && **_isLoaded**){
                    _dirtyColumns.Add(col);
                }
            }
            OnChanged();
        }
    }
}

See how the member variable _isLoaded is false unless the object really is loaded from DB. Subsonic never adds my property to the list of dirty columns.

Your repository Save() method would have to look something like this:

public MyObject Save(Myobject myObject)
{
    myObject.Save();
    myObject= MyObject.SingleOrDefault(x => x.Id == myObject.Id);
    return myObject;
}
Anders Nygaard
+1  A: 

Instead of:

public MyObject Save(Myobject myObject) 
{ 
    myObject.Save(); 
    myObject= MyObject.SingleOrDefault(x => x.Id == myObject.Id); 
    return myObject; 
} 

You can do:

myObject.SetIsLoaded(true);

This saves having to query the database server again.

For example:

myObject.Save();
myObject.Name ="Something else";
myObject.SetIsLoaded(true);
myObject.Save(); 
DaveHogan