using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;
using System.Data.Entity.Spatial;
using System.Linq;
namespace TestLinqTo1C.1
{
    

    [Table("_1SCONST")]
    public partial class 
    {
        [Key]
        public int ROW_ID { get; set; }

        [Required]
        [StringLength(9)]
        public string OBJID { get; set; }

        public int ID { get; set; }

        public DateTime DATE { get; set; }

        [Required]
        [StringLength(255)]
        public string VALUE { get; set; }

        [Required]
        [StringLength(9)]
        public string DOCID { get; set; }

        public int TIME { get; set; }

        public int ACTNO { get; set; }

        public short LINENO_ { get; set; }

        [Required]
        [StringLength(3)]
        public string TVALUE { get; set; }

        public static System.Linq.IQueryable<1.> (int ID, string OBJID, DateTime DATE)
        {
            var  = .;
            var query = (from  in .
                         where .ID == ID && .OBJID == OBJID && .DATE <= DATE
                         orderby .DATE descending, .TIME descending, .DOCID descending, .ROW_ID descending
                         select new 1.{  = .VALUE }).Take(1);

            return query;
        }

        public static DateTime (int ID, string OBJID, DateTime DATE)
        {

            var query = 1..(ID, OBJID, DATE);

            var res = query.SingleOrDefault();
            if (res == null)
                return new DateTime(1, 1, 1);

            if (res. == "  .  .    ")
                return new DateTime(1, 1, 1);

            var str = res.;
            return DateTime.Parse(str.Substring(6, 4) + "-" + str.Substring(3, 2) + "-" + str.Substring(3, 2), System.Globalization.CultureInfo.InvariantCulture);
        }
    }

    public class 
    {

      public  string   { get; set; }
    }

    public partial class 
    {
        public static Model1  = new Model1();

        public const string  = "     0   ";

    }
}
