http://www.cnblogs.com/leotsai/p/aspnet-tests-for-juniors.html
第4题 只是考会不会扩展方法
public static IQueryable<T> WhereNotDeleted<T>(this IQueryable<T> query) where T : Product
{
return query.Where(t => t.IsDeleted == "No");
}
public static IQueryable<Product> WhereNotDeleted(this IQueryable<Product> query)
{
return query.Where(t => t.IsDeleted == "No");
}
第5题 2表关联group by
SELECT a.`Name` NAME,b.`Year` YEAR,b.`Month` MONTH,SUM(b.`Amount`) Icome FROM USER a,Income b WHERE a.`ID`=b.`UserId`
GROUP BY a.`Name`,b.`Year`,b.`Month`
ORDER BY a.`Name`,b.`Year`,b.`Month`
第6题 考linq的2表关联Group By
var rtSource = from a in users from b in incomes where a.Id == b.UserId group new { a, b } by new { a.Name, b.Year, b.Month } into g select new UserIncomeDto() { Name=g.Key.Name,Year=g.Key.Year,Month=g.Key.Month,Income=g.Sum(t=>t.b.Amount)}; return rtSource.ToList();
第7题 mvc内容目前没有接触到
第8题用 Func<Product, string> 来做的吧??
class Product1 { public string Name { get; set; } public string Description { get; set; } public void Validate1() { if (string.IsNullOrEmpty(this.Name)) { throw new Exception("please enter a name for the product"); } if (string.IsNullOrEmpty(this.Description)) { throw new Exception("product description is required"); } } public void Validate2() {
//this.Require(x => x.Name, "please enter a name for the product");
//this.Require(x => x.Description, "product description is required");
this.Require(GetName, "please enter a name for the product"); this.Require(x => { string baba = x.Description + "bbbbb"; return baba; }, "product description is required"); } string GetName(Product1 haha) { return haha.Name; } void Require(Func<Product1, string> aaa, string erro) { if ((aaa(this) + "").Length == 0) Console.WriteLine(erro); else Console.WriteLine(aaa(this)); } }