Delete record. Fire exception

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
 
M

Mr. Arnold

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.
 
S

shapper

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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top