Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/entity-framework/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Entity framework EF databasefirst时如何连接名字和姓氏并在视图中显示为全名_Entity Framework_Ef Database First_Asp.net Mvc 5.1 - Fatal编程技术网

Entity framework EF databasefirst时如何连接名字和姓氏并在视图中显示为全名

Entity framework EF databasefirst时如何连接名字和姓氏并在视图中显示为全名,entity-framework,ef-database-first,asp.net-mvc-5.1,Entity Framework,Ef Database First,Asp.net Mvc 5.1,我想连接名字和姓氏,并在视图中将其显示为全名。我尝试使用usermeta,因为当您再次生成edmx文件时,它不会影响但会导致无法识别的字段出错,知道如何操作吗 public partial class userdetail { public userdetail() { this.orderdetails = new HashSet<orderdetail>(); } public string userid { get; set;

我想连接名字和姓氏,并在视图中将其显示为全名。我尝试使用usermeta,因为当您再次生成edmx文件时,它不会影响但会导致无法识别的字段出错,知道如何操作吗

public partial class userdetail
{
    public userdetail()
    {
        this.orderdetails = new HashSet<orderdetail>();
    }

    public string userid { get; set; }
    public string username { get; set; }
    public string firstname { get; set; }
    public string lastname { get; set; }

    public virtual ICollection<orderdetail> orderdetails { get; set; }
}
然后我创建了一个分部类

[MetadataType(typeof(Usemeta))]
public  partial class userdetail
{
}

只需在视图中添加另一个属性,并将FirstName和LastName连接为只读属性,如下所示:

public string FullName 
{
    get { return FirstName + " " +LastName ;}
}

只需在视图中添加另一个属性,并将FirstName和LastName连接为只读属性,如下所示:

public string FullName 
{
    get { return FirstName + " " +LastName ;}
}

也可以使用表达式体:

public string FullName => FirstName + " " + LastName;

也可以使用表达式体:

public string FullName => FirstName + " " + LastName;