EF 數據查詢(更改默認排序)


數據實體對象

public class ProductInvLocationMapEntity:BaseDomain
    {
        #region Constructors

        public ProductInvLocationMapEntity()
        { }

        #endregion

        #region Properties
        /// <summary>
        /// 
        /// AllowNull: False
        /// Length: 8
        /// </summary>
        //public long Id { get; set; }

        /// <summary>
        /// 商品id
        /// AllowNull: False
        /// Length: 8
        /// </summary>
        public long ProductId { get; set; }

        /// <summary>
        /// 商品貨號
        /// AllowNull: False
        /// Length: 50
        /// </summary>
        public string ProductCode { get; set; }

        /// <summary>
        /// 庫位編號
        /// AllowNull: False
        /// Length: 50
        /// </summary>
        public string LocationLabel { get; set; }

        /// <summary>
        /// 庫位類型
        /// AllowNull: False
        /// Length: 50
        /// </summary>
        public string LocationType { get; set; }

        /// <summary>
        /// 生產日期
        /// AllowNull: False
        /// Length: 8
        /// </summary>
        public DateTime ManufactureDate { get; set; }

        /// <summary>
        /// 已存放數量
        /// AllowNull: False
        /// Length: 4
        /// </summary>
        public int StoredQty { get; set; }

        



        #endregion

        #region override Mehtods

        public override string ToString()
        {
            return base.ToString();
        }

        #endregion

        /// <summary>
        /// 倉庫Id
        /// </summary>
        public long WarehouseId { get; set; }
    }

數據操作方法

/// <summary>
        /// 
        /// </summary>
        /// <param name="product_id"></param>
        /// <param name="manufacture_date"></param>
        /// <returns></returns>
        public Models.EF6_Test.ProductInvLocationMapEntity GetMatchedLocationMap(long product_id,DateTime manufacture_date)
        {

            DateTime maxValue = new DateTime(9999, 12, 31, 23, 59, 59);
#if DEBUG
            this.OpenSqlRawOutput(Console.WriteLine);
#endif
            var matched_entity = this.EntrySet
                .OrderBy(obj=>obj.ModifiedTime)
                .FirstOrDefault(obj => (obj.ProductId == product_id && obj.ManufactureDate == manufacture_date) || (obj.ProductId == product_id && obj.ManufactureDate == maxValue));
            return matched_entity;
        }











免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM