1

I have a C# EF 6 Database First project("DocRetData") that I am using as my "Model" in a VB.Net Web Forms project. I'm also using the "Web Forms Scafolding" extension. I have added a reference to the EF project and then created "New Scaffold Item". Project compiles. When I run it and access the "Default" page it lists items just fine, but when I go to Edit or Create a new item I get System.ArgumentNullException in the GetData() function of ForeignKey_EditField Class. It looks like this:

Public Function GetData() As IQueryable
    Dim entityType = Type.[GetType](Me.DataTypeName)
    Return _db.[Set](entityType).AsQueryable()
End Function

This has to be something do with a reference conflict of some kind, because if I remove Data Project, add the Model as a class within the Web Forms project and go through all the same steps then I don't get the error and can Edit or Create items just fine.

The data structure here is a fairly simple one. The Table(Object) I'm trying to reference here is has the following structure:

[AppSettingID] [int] IDENTITY(1,1) NOT NULL,
[CountyID] [int] NOT NULL,
[Name] [varchar](30) NOT NULL,
[VariableName] [varchar](50) NOT NULL,
[Setting] [varchar](4000) NOT NULL,
[FieldDataTypeID] [int] NOT NULL,

where CountyID and FieldDataTypeID are foreign keys to other tables.

The Error occurs on the Return statement because the entityType is null. The Me.DataTypeName is "DocRetData.County". I'm guessing this has something to do with the way that VB.Net does/does not handle Namespaces but have not been able to track it down.

Thanks

dbl

dblwizard
  • 595
  • 7
  • 26

1 Answers1

0

Im not sure how it would apply to VB but in C# this is the change you need to make if the Type exists in a different class library

  public IQueryable GetData()
  {
            var entityType = Type.GetType(this.DataTypeName + ",DAL");
            return _db.Set(entityType).AsQueryable();
  } 

So in my example my Class Library where my Entities exists is Called DAL. My DataTypeName was "DAL.tbl_Jobs"

So Type.GetType("DAL.tbl_Jobs,DAL") return the Entity Type.

Hope this helps

De Wet Ellis
  • 720
  • 6
  • 7