在linq查询中将Date转换为Shamsi

时间:2015-03-04 13:09:49

标签: c# linq persian

我想在Linq查询中将公历日期转换为Shamsi

这是我的查询

Contex = new RfidReaderEntities1();
var selectall = from myreads in Contex.V_DriverWithReadTags select new { myreads.RfidTagId, myreads.CarType, myreads.Plate, myreads.VisiteDate, myreads.Lname,myreads.shamsidate}; 
dataGridView1.DataSource = selectall.ToList();

我想将myreads.VisiteDate转换为Shamsi日期。

2 个答案:

答案 0 :(得分:0)

首先下载FarsiLibrary.Utils因为它将Gregorian转换为Shamsi而没有任何错误将其DLL文件添加到您的项目中以获取更多信息Here

然后试试这个:

var selectall = from myreads in Contex.V_DriverWithReadTags select new {
            RfidTagId = myreads.RfidTagId,
            CarType = myreads.CarType, 
            Plate = myreads.Plate,
            VisiteDate = PersianDateConverter.ToPersianDate(myreads.VisiteDate), 
            Lname = myreads.Lname,
            shamsidate = myreads.shamsidate
        }; 

答案 1 :(得分:0)

 Contex = new RfidReaderEntities1();


            var selectall = from myreads in Contex.V_DriverWithReadTags select new {
            RfidTagId = myreads.RfidTagId,
            CarType = myreads.CarType, 
            Plate = myreads.Plate,
            VisiteDate = PersianDateConverter.ToPersianDate((DateTime)myreads.VisiteDate), 
           // VisiteDate = myshamsifun.GetShamsiDateTime((DateTime)myreads.VisiteDate), 
            Lname = myreads.Lname,   
        };


            dataGridViewlisttoday.DataSource = selectall.ToList();