部分类,LINQ,接口和VB.NET [英] Partial Classes, LINQ, Interfaces and VB.NET

查看:85
本文介绍了部分类,LINQ,接口和VB.NET的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

好的,我遇到了VB.NET的问题。所以那些VB.NET的维护者,你能帮帮我吗?这是我的问题:我正在使用LINQ to Entities,它也适用于LINQ to SQL,我构建我的edmx文件然后创建一个与其中一个实体同名的Partial Publc类所有细则到现在为止,所以这里来了问题。

Okay, I have ran in to a problem with VB.NET. So all those defenders of VB.NET please can you help me out? Here is my issue: I am using LINQ to Entities, it also works with LINQ to SQL, I build my edmx file I then create a Partial Publc Class of the same name as one of the entities All fine up to now, so here comes the problem.

我需要Partial类来实现Interface Implements Interfaces.IAsset但VB.NET希望在属性的末尾放置Implements Interfaces.IAsset.ID,这当然是在Partial类的生成代码部分,我不能这样做,因为edmx文件是自动生成的,并且将来会改变。

I need the Partial class to implement an Interface Implements Interfaces.IAsset But VB.NET want to place "Implements Interfaces.IAsset.ID" at the end of the property, which of course is in the generated code section of the Partial class, which I can not do as the edmx file is auto generated and will change in the future.

以下是需要排序的代码行:

Here is the line of code that needs sorting:

公共属性ID1()As Integer实现接口。 IAsset.ID

Public Property ID1() As Integer Implements Interfaces.IAsset.ID

在C#中它很好并且可以创造奇迹。那么为什么VB.NET不能实现代码生成类中的接口呢?

In C# it is fine and works wonders. So why can't VB.NET implement an interface that is in the code generated class?

推荐答案

稍微间接一下部分类应该这样做...

A little bit of indirection in the partial class should do the trick...

Public Property AssetId() As Int32 Implements IAsset.AssetId
    Get
        Return Id1
    End Get
    Set(ByVal value As Int32)
        Id1 = value
    End Set
End Property

实现接口的属性调用dbml生成的实际属性。该类基本上有两个id属性,这不是很优雅但是当通过界面访问时你不会知道它们的区别。

The property that implements the interface calls the actual property generated by the dbml. The class will essentially have two id properties, which is not very elegant but when accessed through the interface you won't know the difference.

这篇关于部分类,LINQ,接口和VB.NET的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆