zoukankan      html  css  js  c++  java
  • linq to entity查询,日期格式化

    当从数据库查询数据的同时对取得的数据中日期进行格式化。

    /// <summary>
            /// 同类文章
            /// </summary>
            /// <returns></returns>
            public string SameCategoryArticles(int id)
            {
                int objId = Utility.StrToInt(id, 0);
                //var aCategory = from c in db.Articles where c.ObjectID == objId select c.UserCategoryID;
                var sames = (from a in db.Articles.ToList() join aa in db.Articles on a.UserCategoryID equals aa.UserCategoryID where aa.ObjectID == objId select new { ObjectID = a.ObjectID, ObjectTitle = a.ObjectTitle, CreateTime =a.CreateTime.ToString("yyyy-MM-dd"), VisitedCount = a.VisitedCount }).ToList();
                return JsonConvert.SerializeObject(sames);
            }

    注意点:在利用ToString("yyyy-MM-dd")前必须对model进行转换,转换成Object对象,本文采用db.Articles.ToList()实现,这样就把数据先转换成对象,然后才能调用ToString方法,否则会报错。

  • 相关阅读:
    JS PopupAlert
    JS Navigator
    JS History
    JS Location
    JS Screen
    JS Window
    PTZView
    使用JmDNS发现设备
    Android开发调用webservice方式之一
    解决webservice发布报错Service Unavailable HTTP Error 503. The service is unavailable.
  • 原文地址:https://www.cnblogs.com/wangzl1163/p/6341154.html
Copyright © 2011-2022 走看看