如何使用entityframework将数据时间转换为时间 [英] How to convert datatime to time using in entityframework

查看:218
本文介绍了如何使用entityframework将数据时间转换为时间的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

var std =(来自实体中的sa.MBL_MAST_GRIEVANCE



选择新的

{

sa。状态==1?有效:InActive,

sa.creation_date,

})。ToList();

foreach(标准版中的var p)

{



CMSMobApp edtprod =新的CMSMobApp();

edtprod。 Status =(p.Status);

edtprod.CreatedDate = p.creation_date.ToString();

obj.Add(edtprod);

}



我的尝试:



以上是我的代码 -

creation_date是我的专栏,我获取数据时间数据,我想知道如何转换

此created_date列的日期时间



还有一个问题 -

状态是我的列名,我得到了id喜欢1,2和那里我想使用案例

喜欢当1然后Active其他Inactive如何在entityframework中使用它



请帮助

解决方案

它已经是一个DateTime值 - 所以只需删除ToString调用它就应该正常工作:

 edtprod.CreatedDate = p.creation_date; 


var std = (from sa in Entities.MBL_MAST_GRIEVANCE

select new
{
sa.Status == "1" ? "Active" : "InActive",
sa.creation_date,
}).ToList();
foreach (var p in std)
{

CMSMobApp edtprod = new CMSMobApp();
edtprod.Status = (p.Status);
edtprod.CreatedDate = p.creation_date.ToString();
obj.Add(edtprod);
}

What I have tried:

Above is My Code-
creation_date is my column where i get datatime data and i want to know how to convert
datetime to date of this created_date Column

one more question -
status is my column name where i get id like 1,2 and there i want to use case
like when 1 then Active else Inactive how to use it in entityframework

please help

解决方案

It's already a DateTime value - so just remove the ToString call and it should "just work":

edtprod.CreatedDate = p.creation_date; 


这篇关于如何使用entityframework将数据时间转换为时间的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆