1

As far as I am aware, for the property to be saved in the database it cannot be ReadOnly. IIdentity properties: AuthenticationType, IsAuthenticated and Name are all ReadOnly.

Is making the wrapper to the properties that need to be saved the only solution or there are better ones?

EDIT: I might not have explained my question that well. Here is the sample code for one of the ReadOnly properties, I have added UserName property for the Entity Framework:

Public Property UserName As String
    Get
        Return _userName 
    End Get
    Private Set(value As String)
        userName = value
    End Set

Public ReadOnly Property Name As String Implements System.Security.Principal.IIdentity.Name
    Get
        Return UserName
    End Get
End Property

What I wanted to ask is if there is any better way of doing it.

Minnie
  • 257
  • 3
  • 16

2 Answers2

1

IIdentity properties are read only but the implementation can have setters. If you are using EDMX for mapping you don't have to expose these setters as public.

Edit:

This is possible in C# so hopefully you can use similar approach with VB.NET (I can only read VB code, not write):

public interface ITest {
    string Name { get; }
}

public class Test : ITest {
    public string Name { get; set; }
}

The class offers setter even the interface didn't define it.

Community
  • 1
  • 1
Ladislav Mrnka
  • 360,892
  • 59
  • 660
  • 670
  • Using Code First, not EDMX, but your example is similar to what I have been doing (I've modified my question's UserName property with Get and Private Set so you can see the way I have been doing it). I was just wondering, since I could not find any other way, if there is better way of doing it or not. – Minnie Sep 02 '11 at 14:44
  • In case of code first it should be still same but setter must be visible to your context or configuration class. – Ladislav Mrnka Sep 02 '11 at 14:47
  • Would you code it like this: public string Name { get; **internal** set; }? – Minnie Sep 02 '11 at 14:57
  • Only if you have entities in the same assembly as a context or if you have internals visible to assembly containing the context. – Ladislav Mrnka Sep 02 '11 at 15:07
0

The EF persists objects, not interfaces. Your object can have whatever properties you would like it to have. You cannot add an interface to your entity model, but you can add an object type which implements that interface.

Craig Stuntz
  • 125,891
  • 12
  • 252
  • 273