如何在EntityFramework中更改变量值

时间:2016-06-03 08:59:44

标签: asp.net entity-framework

我正在学习,EntityFramework。

if (c.Status == 1) {  c.StatusString = "Active"; }else{  c.StatusString = "Deactive"; }

我的c.Status值1或0,我想控制我的状态值并写入我的Repeater Line,

示例

<Image source={{uri: 'welcome_notes' }} style={style.cardPicture} />

我可以阅读以及如何编写我的中继线。

感谢。

1 个答案:

答案 0 :(得分:0)

由于您正在创建一个匿名类型(new {}),您基本上可以添加任何内容。

试试这个:

var Sorgu = from c in YonetimDB.iletisim
                        select new {
                            c.id,
                            c.FullName,
                            c.Email,
                            c.Subject,
                            c.Date,
                            c.Status,
                            StatusString = c.Status == 1 ? "Active" : "Deactive"
                               };

更好的解决方案实际上是这样的:

public class sorguModel {
    public int Id { get; set; }
    public string FullName { get; set; }
    public string Email { get; set; }
    public string Subject { get; set; }
    public DateTime Date { get; set; }
    public bool Status { get; set; }
    public string StatusText {
        get{
            return this.Status == 1 ? "Active" : "Deactive";
        }
    }
}

var sorguList = YonetimDB.iletisim
                .select( i => new sorguModel { 
                            Id = c.id,
                            FullName = c.FullName,
                            Email = c.Email,
                            Subject = c.Subject,
                            Date = c.Date, // ASSUMING THE DATE IS A PROPER DATE FORMAT
                            Status = c.Status})
                .ToList();