简体   繁体   English

实体框架如何处理.NET(VB.NET)中的自动实现的属性?

[英]How does Entity Framework handle auto-implemented properties in .NET (VB.NET)?

I am new to EF and have a VB.NET project which has auto-implemented properties. 我是EF的新手,并且拥有一个具有自动实现属性的VB.NET项目。 How does EF handle auto-implemented properties, in that, will I have/run into issues with migrating an existing solution/DB to EF where auto-implemented properties is present? EF如何处理自动实现的属性,在这种情况下,将现有解决方案/数据库迁移到存在自动实现的属性的EF时会遇到问题吗?

(All the existing DB/Solution migrations I've come across so far explicitly state the get & set) (到目前为止,我遇到的所有现有的DB / Solution迁移都明确说明了get&set)

Example: 例:

 Public Property Name As String
 Public Property Owner As String = "DefaultName"
 Public Property Items As New List(Of String) From {"M", "T", "W"}
 Public Property ID As New Guid()

Versus: 与:

Private _Prop2 As String = "Empty"
Property Prop2 As String
Get
    Return _Prop2
End Get
Set(ByVal value As String)
    _Prop2 = value
End Set
End Property

https://docs.microsoft.com/en-us/dotnet/visual-basic/programming-guide/language-features/procedures/auto-implemented-properties https://docs.microsoft.com/zh-cn/dotnet/visual-basic/programming-guide/language-features/procedures/auto-implemented-properties

Thank you so much in advance. 提前非常感谢您。

No you won't have any issues with auto-implemented properties. 不,您不会对自动实现的属性产生任何问题。 It generates those auto props when using DB First. 使用DB First时,它会生成这些自动道具。

I suggest looking into DB First, Code First or Model first. 我建议先研究数据库,代码优先或模型。 It's better to have a more solid link between your DB and code rather than a weak link which requires you to make code/db changes whenever either or is updated 最好在数据库和代码之间建立更牢固的链接,而不是在每次更新或更新时都要求您更改代码/数据库的弱链接

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

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