views:

200

answers:

2

This is the common structure of all of my classes:

public class User
{
    public int ID { get;set; }
    public string User_name { get; set; }
    public string Pass_word { get; set; }
    public string UserTypeCode { get; set; }

    public int SaveOrUpdate()
    {
     int id = -1;

     if (this._ID <=0)
     {
      id = this.Save();
     }
     else
     {
      bool success = this.Update();

      if(success)
      {
       id = this._ID;
      }
      else
      {
       throw new Exception("Update failed!");
      }
     }

     return id;
    }

    private int Save() { }
    private bool Update() { }
    public static User Get(int id) { }
    public static List<User> Get() { }
    public bool Delete() { }
}

I was using these classes smoothly with winforms.

But while working with ASP.NET, when I try to configure the object data source for a GridView, I don't find the method-names in the Data Source Configuration Wizard. I.e. they are not showing up. So my methods became useless.

I can't change this general structure of all of my classes. I have also a code generator written for them. And I must use ObjectDataSources.

My first question is, why don't they show up?

And, what should I do to make them show up?

+1  A: 

I am not quite sure, but you can try to mark this class with DataObjectAttribute and CRUD methods with DataObjectMethodAttribute. I did not use ObjectDataSource for ages, so can forget something.

Mike Chaliy
Adding attributes didn't work.
JMSA
I know, you need special signature.
Mike Chaliy
+3  A: 

ObjectDataSources look for methods within the type specified that match the signature of the update/insert method name and the update/insert parameters provided.

Your SaveOrUpdate method is on an instantiated class, and the ObjectDataSource will not find a matching method signature.

From what you have, if you must use ObjectDataSources, you may want to consider using a wrapper method. Example.

Forgotten Semicolon
+1 from me. Signature is important. So my answer is not correct.
Mike Chaliy