Castle is similar to The Mentalist but more light-hearted.
Synopsis from wikipedia:
Castle follows Nathan Fillion as Richard Castle, a famous mystery novelist who has killed off his main character in his book series and has writer's block. He is called in to help the NYPD solve a copy-cat murder based on one of his novels. Stana Katic co-stars as Detective Kate Beckett. Castle, who becomes interested in Beckett as a potential character for a new book series, uses his connections at the mayor's office and receives permission to continue accompanying Beckett while investigating cases. Castle decides to use Beckett as the model for the main character of his next book series starring "Nikki Heat". Beckett, an avid reader of Castle's books, initially disapproves of having Castle shadow her on her cases, but later warms up and recognizes Castle as a useful resource in solving crimes.
The books Rick Castle is writing in show have also been published: Heat Wave and Naked Heat.