In Beta3 of Entity Framework there was a teaser in the properties window for Entities and their properties. We saw properties for Access, Getter and Setter but they were inactive.
With the latest bits (available in the VS2008 SP1 Beta) those properties have come to life. Here’s what you’ll find and where you’ll find them.
Entity has an Access property that can be set to Internal or Public.
Each property (scalar as well as navigation) has a Getter and Setter that can be Public, Private, Protected or Internal.
EntitySets have a Getter property that can be Public, Private, Protected or Internal. To get to this property, select the EntitySet in the Model Browser.
The settings are dependant on each other. For example if you change an Entity to Internal, but its EntitySet is public , you’ll get this error:
EntityType ‘Customer’ has ‘Internal’ accessibility and EntitySet ‘Customer’ has a get property with ‘Public’ accessibility. EntitySet’s get property must not have less restrictive access than containing EntityType’s access.
You’ll see the impact of these settings as attributes in the model in the generated class. For example, setting the FirstName property’s Setter to Internal results in the a:SetterAccess attribute added to the Property definition in CSDL.
<Property Name="FirstName" Type="String" Nullable="false" MaxLength="50" a:SetterAccess="Internal" />
and in the Customer class, the FirstName’s Set becomes Friend Set, limiting access to it.
<Global.System.Data.Objects.DataClasses.EdmScalarPropertyAttribute(IsNullable:=false), _
Global.System.Runtime.Serialization.DataMemberAttribute()> _
Public Property FirstName() As String
Get
Return Me._FirstName
End Get
Friend Set
Me.OnFirstNameChanging(value)
Me.ReportPropertyChanging("FirstName")
Me._FirstName = Global.System.Data.Objects.DataClasses.StructuralObject.SetValidValue(value, false)
Me.ReportPropertyChanged("FirstName")
Me.OnFirstNameChanged
End Set
End Property
Sign up for my newsletter so you don't miss my conference & Pluralsight course announcements!