您的位置:首页 > 其它

Func<T,T> 委托 与 lambda 使用

2014-04-11 00:18 405 查看
public class Book

{

public int BookId { get; set; }

[Required]

public string Title { get; set; }

public decimal Price { get; set; }

public string Genre { get; set; }

public DateTime PublishDate { get; set; }

public string Description { get; set; }

public int AuthorId { get; set; }

[ForeignKey("AuthorId")]

public Author Author { get; set; }

}

public class BookDto

{

public string Title { get; set; }

public string Author { get; set; }

public string Genre { get; set; }

}

private static readonly Expression<Func<Book, BookDto>> AsBookDto =
x => new BookDto
{
Title = x.Title,
Author = x.Author.Name,
Genre = x.Genre
};

public IQueryable<BookDto> GetBooks()
{
return db.Books.Include(b => b.Author).Select(AsBookDto);
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: