Delete without fetching.

Posts   
 
    
bswami1
User
Posts: 16
Joined: 06-Jan-2005
# Posted on: 10-Jan-2005 18:16:19   

I am a NEWBIE

I tried what is listed under

"Using the entity classes"

Option 2 for updates


CustomerEntity customer = new CustomerEntity();
customer.CustomerID="CHOPS";
customer.IsNew=false;
customer.Delete();            //  <--NOTICE HERE.

for Delete and it seems to query the database for the data of the entity. I used Sql Profiler for finding this.

From the docs, it says

"Note: this will also work for fast deletes."

In these scenario, my experience indicates that I messed/missed something.

I guess I can do the above using a Predicate and that would NOT cause the query for the object data.

Any ideas ?

Other question I had about Templates:

Is there any CodeSmith templates for generating a Predicate Giver class.

For each usertable in the database { for each PK and UK { Provide a method for getting the Predicate. } }

something like public static IPredicateExpresssion CustomerPK (int CustomerID) {

}

public static IPredicateExpression UserInActivityPK(int UserID, int ActivityID) {

}

so that we can reuse this piece of code and once again it can be generated.

May it is not needed at all ? (To my excuse, read line 1. That is catch (Exception ex) for people like me. sunglasses )

Regards:

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39933
Joined: 17-Aug-2003
# Posted on: 10-Jan-2005 21:37:55   

bswami1 wrote:

I am a NEWBIE

I tried what is listed under

"Using the entity classes"

Option 2 for updates


CustomerEntity customer = new CustomerEntity();
customer.CustomerID="CHOPS";
customer.IsNew=false;
customer.Delete();            //  <--NOTICE HERE.

for Delete and it seems to query the database for the data of the entity. I used Sql Profiler for finding this.

Hmm. The fetch seems unlikely to me, as customer.Delete() will create a PK filter using the fields in the entity, it will not read properties. If you step into the code, it will end up in customer.Delete(deleteRestriction) in the CustomerEntityBase class (if you opted for 2-class scenario). From there it calls into CustomerDAO.DeleteCustomer().

From the docs, it says

"Note: this will also work for fast deletes."

In these scenario, my experience indicates that I messed/missed something.

I guess I can do the above using a Predicate and that would NOT cause the query for the object data.

Correct. The code you pasted simply uses the same code as if you would have done:

CustomerEntity customer = new CustomerEntity("CHOPS"); // fetched // do something

customer.Delete();

Other question I had about Templates:

Is there any CodeSmith templates for generating a Predicate Giver class.

For each usertable in the database { for each PK and UK { Provide a method for getting the Predicate. } }

something like public static IPredicateExpresssion CustomerPK (int CustomerID) {

}

public static IPredicateExpression UserInActivityPK(int UserID, int ActivityID) {

}

so that we can reuse this piece of code and once again it can be generated.

There is not such a template, though the classes have build in methods so you don't need these filters that much. simple_smile

Frans Bouma | Lead developer LLBLGen Pro