Delete record. Fire exception

  • Thread starter Thread starter shapper
  • Start date Start date
S

shapper

Hello,

I am deleting a record using linq:

public void DeleteById(Int32 id) {
}

I think I might try to get the record first. And if does no exist to
fire an exception. Correct?
What should be the type of the exception?

Or should I just use something like:
public void Delete(MyEntity entity) {
}

And before I call delete I should try to get it. Something like:

Album album = albumRepository.FindById(id);
if (album != null)
albumRepository.Delete(album);

Thanks,
Miguel
 
shapper said:
Hello,

I am deleting a record using linq:

public void DeleteById(Int32 id) {
}

I think I might try to get the record first. And if does no exist to
fire an exception. Correct?
What should be the type of the exception?

Or should I just use something like:
public void Delete(MyEntity entity) {
}

And before I call delete I should try to get it. Something like:

Album album = albumRepository.FindById(id);
if (album != null)
albumRepository.Delete(album);

So you're going to read for the record. You check for not null and
delete it.

Throwing an exception for record not there on delete? What deleted the
record? Another user got there first?

It doesn't make sense to throw, because record is not there to delete
you're trying to delete. It's gone. You ignore it.
 
So you're going to read for the record. You check for not null and
delete it.

Throwing an exception for record not there on delete? What deleted the
record? Another user got there first?

It doesn't make sense to throw, because record is not there to delete
you're trying to delete. It's gone. You ignore it.

That makes sense. Thank you.
 
Back
Top