TryFindByPrimaryKey in ActiveRecord Castle

How to search a record by primary key, but return null if it does not exist?

public static T FindByPrimaryKeyOrDefault(object id)
{
  try
  {
    return ActiveRecordMediator<T>.FindByPrimaryKey(id);
  }
  catch (NotFoundException)
  {
    return null;
  }
}
+3
source share
1 answer
ActiveRecordMediator<T>.FindByPrimaryKey(id, false);

I will copy such questions into the ActiveRecord wiki .

+6
source

Source: https://habr.com/ru/post/1729678/


All Articles