1

In the entity Data Model I have the following complex type

<EdmComplexTypeAttribute(NamespaceName:="MEMORABLEModel", Name:="EDMspGetContact_Result")>
<DataContractAttribute(IsReference:=True)>
<Serializable()>
Partial Public Class EDMspGetContact_Result
    Inherits ComplexObject
#Region "Factory Method"
.... etc

I am writing an MVC 4.0 app in VB.Net

I want to add validation to the complex type definition in another project in my solution

I have tried to define a partial class in my MVC project but even though it compiles I know it is wrong somehow because the scaffold template won't generate all the properties

I have moved from traditional coding to object oriented coding in the last 6 months and I really struggle with overcoming problems like this. Appreciate a steer on where I am going wrong. I have tried adding a namespace.

<MetadataType(GetType(EDMspGetContact_ResultMD))> _
<ScaffoldTable(True)> _
Partial Public Class EDMspGetContact_Result
    ' Note this class has nothing in it.  It's just here to add the class-level attribute.
End Class

Public Class EDMspGetContact_ResultMD
    '    ' Name the field the same as EF named the property - "FirstName" for example.
    '    ' Also, the type needs to match.  Basically just redeclare it.
    '    ' Note that this is a field.  I think it can be a property too, but fields definitely should work.

    <Required()> _
    <Display(name:="Last Name")> _
    Public LastName As String

End Class
tereško
  • 58,060
  • 25
  • 98
  • 150

1 Answers1

0

Which of the above class definitions is the EF-generated model class? If it is the last one, it needs to be marked as Partial too so that the extension members defined in your partial classes become part of the same class. That might mean altering the T4 template that EF uses to generate the model classes.

That's assuming that you are using database or model first. If you are using code first, I guess you just need to make your main model class partial.

Paul Taylor
  • 5,651
  • 5
  • 44
  • 68
  • The class EDMspGetContact_Result is the EF generated class. I am using database generated stored procedures to get the complex types. They are both declared as partial but the MVC application is not picking up the EDM Class? – user1833564 Nov 18 '12 at 20:11