开发者

TryFindByPrimaryKey in Castle ActiveRecord

开发者 https://www.devze.com 2022-12-17 02:43 出处:网络
How do I search for a record by primary key, but return null if it doesn\'t exist? public static T FindByPrimaryKeyOrDefault(object id)

How do I search for a record by primary key, but return null if it doesn't exist?

public static T FindByPrimaryKeyOrDefault(object id)
{
  try
  {
    return ActiveRecordMediator<T>.FindByPrimaryKey(id);
  }
  catch (NotFoundException)
  {
   开发者_运维知识库 return null;
  }
}


ActiveRecordMediator<T>.FindByPrimaryKey(id, false);

I'll copy questions like these to the ActiveRecord wiki.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号