问题描述
可以为任何人的EDMX设计器类创建一个视图模型提供了一个链接
can anybody provide a link for creating a viewmodel for the edmx designer class
想我的EDMX文件名为School.edmx,它有school.Designer.cs类。
在设计类,我有如下因素的实体对象
suppose my edmx file is named School.edmx and it has school.Designer.cs class. In the designer class i have the folowing entity object
[EdmEntityTypeAttribute(NamespaceName="teamworkModel", Name="User")]
[Serializable()]
[DataContractAttribute(IsReference=true)]
public partial class User : EntityObject
{
#region Primitive Properties
[EdmScalarPropertyAttribute(EntityKeyProperty=true, IsNullable=false)]
[DataMemberAttribute()]
public global::System.Int32 User_Pk
{
get
{
return _User_Pk;
}
set
{
if (_User_Pk != value)
{
OnUser_PkChanging(value);
ReportPropertyChanging("User_Pk");
_User_Pk = StructuralObject.SetValidValue(value);
ReportPropertyChanged("User_Pk");
OnUser_PkChanged();
}
}
}
private global::System.Int32 _User_Pk;
partial void OnUser_PkChanging(global::System.Int32 value);
partial void OnUser_PkChanged();
[EdmScalarPropertyAttribute(EntityKeyProperty=false, IsNullable=false)]
[DataMemberAttribute()]
[Required(ErrorMessage="Please enter your name")]
[StringLength(20,ErrorMessage="Name cannot exceed 20 characters")]
[RegularExpression(@"^([a-zA-Z0-9 \.\&\'\-]+)$", ErrorMessage = "Invalid name")]
public global::System.String User_Name
{
get
{
return _User_Name;
}
set
{
OnUser_NameChanging(value);
ReportPropertyChanging("User_Name");
_User_Name = StructuralObject.SetValidValue(value, false);
ReportPropertyChanged("User_Name");
OnUser_NameChanged();
}
}
private global::System.String _User_Name;
partial void OnUser_NameChanging(global::System.String value);
partial void OnUser_NameChanged();
[EdmScalarPropertyAttribute(EntityKeyProperty=false, IsNullable=false)]
[DataMemberAttribute()]
[Email(ErrorMessage="Invalid email address")]
[Required(ErrorMessage="Please enter email address")]
public global::System.String User_Mail_Id
{
get
{
return _User_Mail_Id;
}
set
{
OnUser_Mail_IdChanging(value);
ReportPropertyChanging("User_Mail_Id");
_User_Mail_Id = StructuralObject.SetValidValue(value, false);
ReportPropertyChanged("User_Mail_Id");
OnUser_Mail_IdChanged();
}
}
private global::System.String _User_Mail_Id;
partial void OnUser_Mail_IdChanging(global::System.String value);
partial void OnUser_Mail_IdChanged();
[EdmScalarPropertyAttribute(EntityKeyProperty=false, IsNullable=false)]
[DataMemberAttribute()]
[Required(ErrorMessage="Please enter password")]
[StringLength(20,ErrorMessage="Password cannot exceed 20 characters")]
[RegularExpression(@"^([a-zA-Z0-9 \.\&\'\-]+)$", ErrorMessage = "Invalid password")]
public global::System.String User_Password
{
get
{
return _User_Password;
}
set
{
OnUser_PasswordChanging(value);
ReportPropertyChanging("User_Password");
_User_Password = StructuralObject.SetValidValue(value, false);
ReportPropertyChanged("User_Password");
OnUser_PasswordChanged();
}
}
private global::System.String _User_Password;
partial void OnUser_PasswordChanging(global::System.String value);
partial void OnUser_PasswordChanged();
[EdmScalarPropertyAttribute(EntityKeyProperty=false, IsNullable=false)]
[DataMemberAttribute()]
public global::System.DateTime User_Creation_Date
{
get
{
return _User_Creation_Date;
}
set
{
OnUser_Creation_DateChanging(value);
ReportPropertyChanging("User_Creation_Date");
_User_Creation_Date = StructuralObject.SetValidValue(value);
ReportPropertyChanged("User_Creation_Date");
OnUser_Creation_DateChanged();
}
}
private global::System.DateTime _User_Creation_Date;
partial void OnUser_Creation_DateChanging(global::System.DateTime value);
partial void OnUser_Creation_DateChanged();
我在上面的实体对象以下各列(User表)User_PK,User_Name的,USER_PASSWORD,USER_EMAIL_ID .....
I have the following columns in the above entity object (User table)User_PK,User_Name,User_Password,User_Email_ID.....
请任何人都可以提出如何创建上述实体对象的视图模型包含除USER_PASSWORD和USER_EMAIL_ID上述所有列,因为我需要用它作为强类型的ViewModel我view.I还需要使用另一个表中同样的视图模型与选定的列....
Please can anyone suggest how to create a viewmodel for the above entity object that contains all the above columns except User_Password and User_Email_ID because i need to use it as strongly typed viewmodel for my view.I also need to use another table in the same viewmodel with selected columns....
我已经经历了很多documents..i历程已经花了1天半此
任何人可以帮助..
我知道这个问题的一再要求,但我cannt发现做正确的方式...
谢谢
i had gone through a lot of documents..i already spent 1 and half day for this can anybody help..i know this question is asked repeatedly but i cannt find the right way in doing it...Thanks
推荐答案
编辑:修改回答关于其他实体额外的属性注释
Modified to answer comment about extra properties from other Entities
这可能有助于
public class UserViewModel
{
public int Pk{get;private set;}
public string Name{get;set;}
public DateTime CreationDate{get;set;}
public string ProjectName{get;set;}
public DateTime ProjectCreated{get;set;}
}
该视图模型是你的实体平铺版本。
The ViewModel is a flattened version of you entities.
这篇关于如何创建一个视图模型和地图的EDMX设计器类的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!