简体   繁体   English

LInq to SQL - Partial Class - C#

[英]LInq to SQL - Partial Class - C#

I have a system with 2 different projects, one is called LINQ_Extensions and the other is ORM_Linq. 我有一个包含2个不同项目的系统,一个叫做LINQ_Extensions,另一个是ORM_Linq。

On ORM_Linq i have the LINQ diagram with the SQL tables "converted" in clases. 在ORM_Linq上,我有LINQ图,其中SQL表在“clased”中被“转换”。 One of the Class is called "Tipos_Pago" 其中一个被称为“Tipos_Pago”

In the other project i have another class (partial class) "Tipos_Pago". 在另一个项目中,我有另一个类(部分类)“Tipos_Pago”。 I want to use the method OnValidate to validate the properties include in the class "Tipos_Pago", so i create this partial class. 我想使用方法OnValidate来验证“Tipos_Pago”类中的属性包含,所以我创建了这个分部类。

In the 2 projects i put the same NameSpace "ORM_Linq"(I changed the NameSpace of the project "LINQ_Extensions" to have the same of the project "ORM_Linq") 在2个项目中,我将相同的NameSpace“ORM_Linq”(我更改了项目“LINQ_Extensions”的NameSpace以使项目“ORM_Linq”相同)

After those chages, Visual Studio give me this error: 在这些chages之后,Visual Studio给出了这个错误:

Error 1 No defining declaration found for implementing declaration of partial method 'ORM_Linq.Tipos_Pago.OnValidate(System.Data.Linq.ChangeAction)' C..\\Tipos_Pago.cs 13 22 Extensiones_Linq 错误1未找到实现部分方法声明的定义声明'ORM_Linq.Tipos_Pago.OnValidate(System.Data.Linq.ChangeAction)'C .. \\ Tipos_Pago.cs 13 22 Extensiones_Linq

I don't have any Idea of what happend, can someone help me? 我对发生的事情一无所知,能有人帮助我吗?

Thanks, sorry for my poor english 谢谢,抱歉我的英语不好

This is the code in the partial class: 这是部分类中的代码:

namespace ORM_Linq
{
    public partial class Tipos_Pago
    {

        partial void OnValidate(System.Data.Linq.ChangeAction action)
        {
         //Valid code
        }   
    }
}

You can't implement a partial across 2 projects, since they have to be compiled together, the partial declarations must all be in the same project. 您不能在两个项目中实现部分,因为它们必须一起编译, partial声明必须全部在同一个项目中。

This same rule applies for methods and classes. 同样的规则适用于方法和类。

You need to create your partial implementation in the same project as the designer-generated classes. 您需要在与设计器生成的类相同的项目中创建部分实现。

From the Microsoft documentation : 从Microsoft 文档

All partial-type definitions meant to be parts of the same type must be defined in the same assembly and the same module (.exe or .dll file). 必须在同一个程序集和相同的模块(.exe或.dll文件)中定义所有部分类型定义,即相同类型的部分。 Partial definitions cannot span multiple modules. 部分定义不能跨越多个模块。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM