Hi Franz!!!!
Thanks for your help... I had to chage your code a little (had to use a for loop with a counter). Some how the fields collection doesn't seem to be a collection, at least not in the entities I'm using. I don't think this has any thing to do with the fact that I'm using VB instead of C#....
Any ways.. I still have problem... Now I'm getting an error...
Perhaps if I explain what I'm trying to do you could help me out a little...
I want to be able to persist any entity in this DB ( as long as that entity exists in the DB) using a single web method. Furthermore, I don't want to reference the LLBLGen generated DLL's containing those entities (except for 3 entities that I use to control the whole thing.. I mean they containg some "metadata"). So I'm trying to use reflection....
This is the code I've come up with...
<WebMethod(Description:="Recieves an IEntity2 Object as an XML String and its type and persits it to the Sicronization Repository")> _
Public Sub SinchronizeEntity(ByVal x As String, ByVal TheType As String)
Dim TheDynamicClass As New DC_DYNAMIC_CLASSESEntity
TheDynamicClass.DC_Type = TheType
Dim TheAdapter As DataAccessAdapter
TheAdapter = New DataAccessAdapter("data source=JMURILLO;initial catalog=server;User ID=xxxxxxxxx;Password=xxxxxxxxx;persist security info=False;packet size=4096", True, CatalogNameUsage.ForceName, "CISCRMSinc")
TheAdapter.FetchEntityUsingUniqueConstraint(TheDynamicClass, TheDynamicClass.ConstructFilterForUCDC_Type())
Dim AssemblyContainingEntity As [Assembly] = _
[Assembly].LoadFrom(TheDynamicClass.DC_Location)
Dim TypeToLoad As Type = AssemblyContainingEntity.GetType(TheDynamicClass.DC_Type)
Dim TheGenericEntity As Object
TheGenericEntity = Activator.CreateInstance(TypeToLoad)
Dim TheSourceEntity As IEntity2 = CType(TheGenericEntity, IEntity2)
TheSourceEntity.ReadXml(x)
Dim i As Int16
For i = 0 To TheSourceEntity.Fields.Count - 1
TheSourceEntity.Fields(0).IsChanged = True
Next
TheSourceEntity.IsNew = True
TheSourceEntity.Fields.IsDirty = True
Try
If TheAdapter.SaveEntity(TheSourceEntity) Then
TheAdapter.CloseConnection()
Else
TheAdapter.CloseConnection()
End If
Catch ex As Exception
End Try
It seems to work fine, but, when I save the entity, I get a Null Reference Exception
The Try Catch block at the end is just to be able to view the exception when I'm debugging.
Any ideas????