DataPortal.Delete<T>(object criteria) Why not?

DataPortal.Delete<T>(object criteria) Why not?

Old forum URL: forums.lhotka.net/forums/t/3283.aspx


phucphlq posted on Saturday, July 28, 2007

I implemented an Editable Root, it has DataPortal_Delete method

private void DataPortal_Delete(int Id)

{

}

And

public static void Delete(int Id)

{

            DataPortal.Delete(Id);

}

 It don’t work because “DataPortal.Delete” find method by GetObjectType(object criteria), while criteria’s type is int.

 I think Csla should be implemented DataPortal.Delete<T>(object criteria) method

 Thanks.

RockfordLhotka replied on Saturday, July 28, 2007

Criteria must always be transported to the DataPortal_XYZ methods in a criteria object of your design. You can never pass simple types directly.

The reason is that the criteria always includes at least two pieces of information:

  1. The type of the business object
  2. The criteria data you provide

Even in the case of Create() or Fetch(), both those pieces of information are carried, and you can not pass a simple type to those methods either. You can pass no parameter at all, or you can pass a criteria object of your design.

In the case of delete, it is hard to see where it could ever make sense to pass no parameter, because you wouldn't know what to delete, and so the only option is to pass a criteria object of your design.

phucphlq replied on Sunday, July 29, 2007

Currently, Csla has DataPortal.Fetch<T>(object criteria) with T provides The type of the business object and criteria provides The criteria data you provide.

I always call DataPortal.Fetch<T>(int id) with simple type int, it’s OK!

I think DataPortal.Delete<T> the same way.

Thanks Rock and Csla.

RockfordLhotka replied on Sunday, July 29, 2007

If that works you are lucky. It is not designed to work, and doing that is not supported.

 

In fact, the type int is a “magic type” if you look at how the data portal operates. No other primitive type will work like that.

 

I _strongly_ recommend you only pass criteria objects as parameters. You are just asking for your code to break in some future release of CSLA if you pass anything else.

 

Rocky

 

 

From: Pham Huu Le Quoc Phuc [mailto:cslanet@lhotka.net]
Sent: Sunday, July 29, 2007 10:12 PM
To: rocky@lhotka.net
Subject: RE: [CSLA .NET] DataPortal.Delete(object criteria) Why not?

 

Currently, Csla has DataPortal.Fetch<T>(object criteria) with T provides The type of the business object and criteria provides The criteria data you provide.

I always call DataPortal.Fetch<T>(int id) with simple type int, it’s OK!

I think DataPortal.Delete<T> the same way.

Thanks Rock and Csla.

 


From: RockfordLhotka [mailto:cslanet@lhotka.net]
Sent: Saturday, July 28, 2007 10:03 PM
To: phucphlq@dsp.com.vn
Subject: Re: [CSLA .NET] DataPortal.Delete<T>(object criteria) Why not?

 

Criteria must always be transported to the DataPortal_XYZ methods in a criteria object of your design. You can never pass simple types directly.

The reason is that the criteria always includes at least two pieces of information:

  1. The type of the business object
  2. The criteria data you provide

Even in the case of Create() or Fetch(), both those pieces of information are carried, and you can not pass a simple type to those methods either. You can pass no parameter at all, or you can pass a criteria object of your design.

In the case of delete, it is hard to see where it could ever make sense to pass no parameter, because you wouldn't know what to delete, and so the only option is to pass a criteria object of your design.

 



Copyright (c) Marimer LLC