Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/452.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
Wcf EntityFramework生成的类_Wcf_Entity Framework 4.1_Data Annotations - Fatal编程技术网

Wcf EntityFramework生成的类

Wcf EntityFramework生成的类,wcf,entity-framework-4.1,data-annotations,Wcf,Entity Framework 4.1,Data Annotations,我有一个EF模型,我已经使用数据库优先方法生成。在设计器中,我使用DBContext对象创建了一个“代码生成项”。这创建了一个为我的表(我想要)生成POCO类的模板 我一直在使用这些类来编写WCF和其中的DataAnnotation属性,它们工作得很好。我保存了这个文件的一个副本,如果重新生成模型,我只需将旧代码粘贴到新创建的模型生成的类中,并更新任何新属性 我试着更进一步。无论何时更改模型,类都会重新生成,属性也会丢失。我试图做的是在我的项目中创建一个单独的文件夹,使用相同的类名按名称空间限定

我有一个EF模型,我已经使用数据库优先方法生成。在设计器中,我使用DBContext对象创建了一个“代码生成项”。这创建了一个为我的表(我想要)生成POCO类的模板

我一直在使用这些类来编写WCF和其中的DataAnnotation属性,它们工作得很好。我保存了这个文件的一个副本,如果重新生成模型,我只需将旧代码粘贴到新创建的模型生成的类中,并更新任何新属性

我试着更进一步。无论何时更改模型,类都会重新生成,属性也会丢失。我试图做的是在我的项目中创建一个单独的文件夹,使用相同的类名按名称空间限定它。我基本上会将生成的POCO类中更改的任何属性复制到我创建的新文件夹中的另一个类中,并简单地添加我需要的任何属性。不过,这几乎与上面第二段中的做法相同。然而,如果有大型数据库模型,这可能会变得单调乏味,并且容易出错

我想做的是在不丢失属性的情况下模拟生成模型。是的,我知道——吃着我的蛋糕,也吃着它

有什么想法吗

我尝试添加好友类,但没有成功

数据很好地通过网络传输,但是在添加了buddy类之后,数据注释不起作用。

using System;
using System.Collections.Generic;
using System.ServiceModel;
using System.Runtime.Serialization;
using System.ComponentModel.DataAnnotations;
using DataAnnotationsExtensions;

namespace YeagerTechModel
{
    [MetadataType(typeof(Customer_Validation))]
    public partial class Customer
    {

    }

    public partial class Customer_Validation
    {
        [Serializable]
        [DataContract(IsReference = true)]
        public class Customer1
        {
            public Customer1()
            {
                this.Projects = new HashSet<Project>();
            }

            [DataMember]
            public short CustomerID { get; set; }

            [DataMember]
            [Required]
            [StringLength(50)]
            [DataType(DataType.EmailAddress)]
            [Email]
            public string Email { get; set; }

            [DataMember]
            [StringLength(50, MinimumLength = 3, ErrorMessage = "Must have a minimum length of 3.")]
            [DataType(DataType.Text)]
            public string Company { get; set; }

            [DataMember]
            [StringLength(50, MinimumLength = 3, ErrorMessage = "Must have a minimum length of 3.")]
            [DataType(DataType.Text)]
            public string FirstName { get; set; }

            [DataMember]
            [StringLength(50, MinimumLength = 3, ErrorMessage = "Must have a minimum length of 3.")]
            [DataType(DataType.Text)]
            public string LastName { get; set; }

            [DataMember]
            [StringLength(50, MinimumLength = 3, ErrorMessage = "Must have a minimum length of 3.")]
            [DataType(DataType.Text)]
            public string Address1 { get; set; }

            [DataMember]
            [StringLength(50)]
            [DataType(DataType.Text)]
            public string Address2 { get; set; }

            [DataMember]
            [StringLength(50, MinimumLength = 3, ErrorMessage = "Must have a minimum length of 3.")]
            [DataType(DataType.Text)]
            public string City { get; set; }

            [DataMember]
            [StringLength(2, MinimumLength = 2, ErrorMessage = "Must have a length of 2.")]
            [DataType(DataType.Text)]
            public string State { get; set; }

            [DataMember]
            [StringLength(10)]
            [DataType(DataType.Text)]
            [RegularExpression(@"^\d{5}(-\d{4})?$", ErrorMessage = "Invalid Zip")]
            public string Zip { get; set; }

            [DataMember]
            [StringLength(12)]
            [DataType(DataType.PhoneNumber)]
            [RegularExpression(@"^\s*([\(]?)\[?\s*\d{3}\s*\]?[\)]?\s*[\-]?[\.]?\s*\d{3}\s*[\-]?[\.]?\s*\d{4}$", ErrorMessage = "Invalid Phone")]
            public string HomePhone { get; set; }

            [DataMember]
            [StringLength(12)]
            [DataType(DataType.PhoneNumber)]
            [RegularExpression(@"^\s*([\(]?)\[?\s*\d{3}\s*\]?[\)]?\s*[\-]?[\.]?\s*\d{3}\s*[\-]?[\.]?\s*\d{4}$", ErrorMessage = "Invalid Phone")]
            public string CellPhone { get; set; }

            [DataMember]
            [StringLength(100)]
            [DataType(DataType.Url)]
            [Url]
            public string Website { get; set; }

            [DataMember]
            [StringLength(50)]
            [DataType(DataType.EmailAddress)]
            [Email]
            public string IMAddress { get; set; }

            [DataMember]
            public System.DateTime CreatedDate { get; set; }

            [DataMember]
            public Nullable<System.DateTime> UpdatedDate { get; set; }

            [DataMember]
            public virtual ICollection<Project> Projects { get; set; }
        }
    }
}
我想我可能需要改变我的服务方法,将客户验证对象包括在内,而不是客户,并对客户执行同样的操作

我正要进行此更改,但在我的服务方法中的以下代码片段上遇到了障碍(这甚至是在我更改了DbContext的定义之后,当然是另一个代码生成的类)。p.CustomerID上存在设计时编译错误。它不存在

IQueryable<**Customer_Validation**> customer = DbContext.Customers.Where(p => **p.CustomerID** > 0);


 public DbSet<**Customer_Validation**> Customers { get; set; }
IQueryable customer=DbContext.Customers.Where(p=>**p.CustomerID**>0);
公共数据库集客户{get;set;}
为了让数据注释正常工作,我缺少了什么?非常感谢您的帮助:)

我的客户类别有以下内容。

using System;
using System.Collections.Generic;
using System.ServiceModel;
using System.Runtime.Serialization;
using System.ComponentModel.DataAnnotations;
using DataAnnotationsExtensions;

namespace YeagerTechModel
{
    [MetadataType(typeof(Customer_Validation))]
    public partial class Customer
    {

    }

    public partial class Customer_Validation
    {
        [Serializable]
        [DataContract(IsReference = true)]
        public class Customer1
        {
            public Customer1()
            {
                this.Projects = new HashSet<Project>();
            }

            [DataMember]
            public short CustomerID { get; set; }

            [DataMember]
            [Required]
            [StringLength(50)]
            [DataType(DataType.EmailAddress)]
            [Email]
            public string Email { get; set; }

            [DataMember]
            [StringLength(50, MinimumLength = 3, ErrorMessage = "Must have a minimum length of 3.")]
            [DataType(DataType.Text)]
            public string Company { get; set; }

            [DataMember]
            [StringLength(50, MinimumLength = 3, ErrorMessage = "Must have a minimum length of 3.")]
            [DataType(DataType.Text)]
            public string FirstName { get; set; }

            [DataMember]
            [StringLength(50, MinimumLength = 3, ErrorMessage = "Must have a minimum length of 3.")]
            [DataType(DataType.Text)]
            public string LastName { get; set; }

            [DataMember]
            [StringLength(50, MinimumLength = 3, ErrorMessage = "Must have a minimum length of 3.")]
            [DataType(DataType.Text)]
            public string Address1 { get; set; }

            [DataMember]
            [StringLength(50)]
            [DataType(DataType.Text)]
            public string Address2 { get; set; }

            [DataMember]
            [StringLength(50, MinimumLength = 3, ErrorMessage = "Must have a minimum length of 3.")]
            [DataType(DataType.Text)]
            public string City { get; set; }

            [DataMember]
            [StringLength(2, MinimumLength = 2, ErrorMessage = "Must have a length of 2.")]
            [DataType(DataType.Text)]
            public string State { get; set; }

            [DataMember]
            [StringLength(10)]
            [DataType(DataType.Text)]
            [RegularExpression(@"^\d{5}(-\d{4})?$", ErrorMessage = "Invalid Zip")]
            public string Zip { get; set; }

            [DataMember]
            [StringLength(12)]
            [DataType(DataType.PhoneNumber)]
            [RegularExpression(@"^\s*([\(]?)\[?\s*\d{3}\s*\]?[\)]?\s*[\-]?[\.]?\s*\d{3}\s*[\-]?[\.]?\s*\d{4}$", ErrorMessage = "Invalid Phone")]
            public string HomePhone { get; set; }

            [DataMember]
            [StringLength(12)]
            [DataType(DataType.PhoneNumber)]
            [RegularExpression(@"^\s*([\(]?)\[?\s*\d{3}\s*\]?[\)]?\s*[\-]?[\.]?\s*\d{3}\s*[\-]?[\.]?\s*\d{4}$", ErrorMessage = "Invalid Phone")]
            public string CellPhone { get; set; }

            [DataMember]
            [StringLength(100)]
            [DataType(DataType.Url)]
            [Url]
            public string Website { get; set; }

            [DataMember]
            [StringLength(50)]
            [DataType(DataType.EmailAddress)]
            [Email]
            public string IMAddress { get; set; }

            [DataMember]
            public System.DateTime CreatedDate { get; set; }

            [DataMember]
            public Nullable<System.DateTime> UpdatedDate { get; set; }

            [DataMember]
            public virtual ICollection<Project> Projects { get; set; }
        }
    }
}
使用系统;
使用System.Collections.Generic;
使用System.ServiceModel;
使用System.Runtime.Serialization;
使用System.ComponentModel.DataAnnotations;
使用数据注释;
命名空间技术模型
{
[元数据类型(类型(客户验证))]
公共部分类客户
{
}
公共部分类客户验证
{
[可序列化]
[DataContract(IsReference=true)]
公共类客户1
{
公共客户1()
{
this.Projects=newhashset();
}
[数据成员]
公共短客户ID{get;set;}
[数据成员]
[必需]
[长度(50)]
[数据类型(数据类型.电子邮件地址)]
[电邮]
公共字符串电子邮件{get;set;}
[数据成员]
[StringLength(50,MinimumLength=3,ErrorMessage=“必须具有3的最小长度。”)]
[数据类型(DataType.Text)]
公共字符串公司{get;set;}
[数据成员]
[StringLength(50,MinimumLength=3,ErrorMessage=“必须具有3的最小长度。”)]
[数据类型(DataType.Text)]
公共字符串名{get;set;}
[数据成员]
[StringLength(50,MinimumLength=3,ErrorMessage=“必须具有3的最小长度。”)]
[数据类型(DataType.Text)]
公共字符串LastName{get;set;}
[数据成员]
[StringLength(50,MinimumLength=3,ErrorMessage=“必须具有3的最小长度。”)]
[数据类型(DataType.Text)]
公共字符串地址1{get;set;}
[数据成员]
[长度(50)]
[数据类型(DataType.Text)]
公共字符串地址2{get;set;}
[数据成员]
[StringLength(50,MinimumLength=3,ErrorMessage=“必须具有3的最小长度。”)]
[数据类型(DataType.Text)]
公共字符串City{get;set;}
[数据成员]
[StringLength(2,MinimumLength=2,ErrorMessage=“必须具有2的长度。”)]
[数据类型(DataType.Text)]
公共字符串状态{get;set;}
[数据成员]
[条次建议修正案(10)]
[数据类型(DataType.Text)]
[正则表达式(@“^\d{5}(-\d{4})?$”,ErrorMessage=“无效Zip”)]
公共字符串Zip{get;set;}
[数据成员]
[条次建议修正案(12)]
[数据类型(数据类型.电话号码)]
[RegularExpression(@“^\s*([\(]?)\[?\s*\d{3}\s*\]?[\])?\s*[\-]?[\.]?\s*\d{3}\s*[\-]?[\.]\s*\d{4}$”,ErrorMessage=“无效电话”)]
公共字符串家庭电话{get;set;}
[数据成员]
[条次建议修正案(12)]
[数据类型(数据类型.电话号码)]
[RegularExpression(@“^\s*([\(]?)\[?\s*\d{3}\s*\]?[\])?\s*[\-]?[\.]?\s*\d{3}\s*[\-]?[\.]\s*\d{4}$”,ErrorMessage=“无效电话”)]
公共字符串{get;set;}
[数据成员]
[长度(100)]
[数据类型(DataType.Url)]
[网址]
公共字符串网站{get;set;}
[数据成员]
[长度(50)]
[数据类型(数据类型.电子邮件地址)]
[电邮]
公共字符串IMAddress{get;set;}
[数据成员]
public System.DateTime CreatedDate{get;set;}
[数据成员]
公共可为Null的UpdateDate{get;set;}
[数据成员]
公共虚拟集成电路
IEnumerable<YeagerTechModel.Customer> customerList = db.GetCustomers();

                    return View(new GridModel<YeagerTechModel.Customer>
                    {
                        Data = customerList
                    });
@model Telerik.Web.Mvc.GridModel<YeagerTechModel.Customer>
@{
    ViewBag.Title = "Customer Index";
}
<h2>
    Customer Index</h2>
@(  Html.Telerik().Grid<YeagerTechModel.Customer>(Model.Data)
      .Name("Customers")
            .DataKeys(dataKeys => dataKeys.Add(o => o.CustomerID)
                                            .RouteKey("CustomerID"))
                .ToolBar(commands => commands.Insert().ButtonType(GridButtonType.Text).ImageHtmlAttributes(new { style = "margin-left:0" }))
      .Columns(columns =>
            {
                columns.Bound(o => o.CustomerID).Hidden(true);
                columns.Command(commands =>
                {
                    commands.Edit().ButtonType(GridButtonType.Text);
                }).Width(200).Title("Command");
                columns.Bound(o => o.Email).Width(200).Filterable(false);
                columns.Bound(o => o.Company).Width(200).Filterable(false);
                columns.Bound(o => o.FirstName).Width(100).Title("FName").Filterable(false);
                columns.Bound(o => o.LastName).Width(100).Title("LName").Filterable(false);
                columns.Bound(o => o.Address1).Width(200).Title("Addr1").Filterable(false).Sortable(false);
                columns.Bound(o => o.Address2).Width(100).Title("Addr2").Filterable(false).Sortable(false);
                columns.Bound(o => o.City).Width(100);
                columns.Bound(o => o.State).Width(40).Title("ST");
                columns.Bound(o => o.Zip).Width(60);
                columns.Bound(o => o.HomePhone).Width(120).Filterable(false).Sortable(false);
                columns.Bound(o => o.CellPhone).Width(120).Filterable(false).Sortable(false);
                columns.Bound(o => o.Website).Width(100).Filterable(false).Sortable(false);
                columns.Bound(o => o.IMAddress).Width(100).Filterable(false).Sortable(false);
                columns.Bound(o => o.CreatedDate).Format("{0:MM/dd/yyyy}").ReadOnly(true).Width(120).Filterable(false).Sortable(false);
                columns.Bound(o => o.UpdatedDate).Format("{0:MM/dd/yyyy}").ReadOnly(true).Width(120).Filterable(false).Sortable(false);
            }).DataBinding(dataBinding =>
                dataBinding.Ajax()
                        .Insert("_InsertAjaxEditing", "Customer")
                        .Update("_SaveAjaxEditing", "Customer"))
    .Editable(editing => editing.Mode(GridEditMode.InLine))
    .Pageable()
    .Sortable()
    .Filterable()
    .Scrollable()
 )