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; }
}
{
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); }
相关文章推荐
- action<> func<> 这2个委托使用和理解
- 使用Func<T1, T2, TResult> 委托返回匿名对象
- c#中Action<T>和Func<T>委托
- Func<T1, T2, TResult> 泛型委托
- 泛型Action<T>委托和Func<T>委托是系统定义的两个泛型委托
- C#中的Action<T>、Func<T>委托和Lambda表达式
- C# Func<>委托
- 如何声明和使用 Func<T1, T2, TResult> 委托
- 浅析C#中的Func<>委托
- Func<T,TResult>泛型委托
- C#委托的简单学习:定义委托和使用、Func<int f1,out r1>、给自定义的类或数组排序(冒泡排序)
- C#.NET的Linq查询、lambda、委托:Func<>和Action
- 使用Func<>和Action简化委托
- Func<TResult>委托,Action 委托,Tuple 类
- Func<T, ..., TResult> 委托 实现方法嵌套
- C#中的Action<>和Func<>以及传统的委托
- Func<T, TResult> 委托使用详解
- Func<T, TResult>泛型委托
- C# 新委托使用方法 Lambda表达式,运算符 =>
- Action<T>和Func<T>泛型委托