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 不从部分类元数据应用数据批注验证_Entity Framework_Validation_Webforms_Data Annotations - Fatal编程技术网

Entity framework 不从部分类元数据应用数据批注验证

Entity framework 不从部分类元数据应用数据批注验证,entity-framework,validation,webforms,data-annotations,Entity Framework,Validation,Webforms,Data Annotations,我正在使用Entity Framework 5和数据库优先方法开发一个ASP.NET Web表单应用程序。我有一个单独的项目,用于生成实体的数据访问层。在这个项目中,我有一个目录ModelPartials,用于应用我的数据注释。例如,我创建了客户机实体: namespace DataAccessLayer { using System; using System.Collections.Generic; using System.ComponentModel.DataAnnotations;

我正在使用
Entity Framework 5
数据库优先
方法开发一个
ASP.NET Web表单
应用程序。我有一个单独的项目,用于生成实体的数据访问层。在这个项目中,我有一个目录
ModelPartials
,用于应用我的
数据注释。例如,我创建了
客户机
实体:

namespace DataAccessLayer
{
using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;

public partial class Client
{
    public Client()
    {
        this.Accounts = new HashSet<Account>();
        this.ClientHistories = new HashSet<ClientHistory>();
    }

    public int ClientId { get; set; }
    public string FirstName { get; set; }
    public string LastName { get; set; }
    //the class continues...
问题来了。在我的
aspx
文件中,我必须将该类添加到
ItemType
。如果我尝试在
ModelPartials
中导航到分部类,如下所示:

ItemType="DataAccessLayer.ModelPartials.Client" 
我得到一个错误,这个类不包含我使用的属性的定义。如果我将其更改为:

ItemType="DataAccessLayer.ModelPartials.ClientMetaData"
然后识别我的属性,但在我的后端,我的
Update
方法期望
Client
作为参数:

public void Update(Client client)
    {

        if (ModelState.IsValid)
        //more code...
我不认为我必须将其更改为
ClientMetaData
。我能让它工作的唯一方法是将
DataAnnotations
直接应用到自动创建的实体中,但这使得使用元数据等的整个想法毫无用处


我在这里遗漏了什么来实现此功能?

您的分部类必须驻留在同一名称空间中,分部才能工作

因此,在您的示例中,将名称空间设置为DataAccessLayer


metada可以位于不同的名称空间。

谢谢,我已经手动更改了名称空间,效果很好。你知道仅仅从名称空间中删除额外的部分是好的还是有更好的方法吗?删除额外的部分,保存并重新编译就可以了。不要让VS使用intellisense helper thingie更改名称空间。
public void Update(Client client)
    {

        if (ModelState.IsValid)
        //more code...