Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ObjectReader.Create(List(of Object)) fails #67

Open
danj1980 opened this issue Jan 8, 2019 · 2 comments
Open

ObjectReader.Create(List(of Object)) fails #67

danj1980 opened this issue Jan 8, 2019 · 2 comments

Comments

@danj1980
Copy link

danj1980 commented Jan 8, 2019

Works great when I pass List(Of StronglyTypedObjectClass).

But when I pass a List(Of Object), it fails to return valid content and doesn't throw any exceptions, such as a NotSupportedException.

Dim NewCDRs As New List(Of object)
Dim NewCDR As New CustomerContractCall
NewCDR.Property1 = something
NewCDRs.Add(NewCDR)
Dim Reader = FastMember.ObjectReader.Create(NewCDRs)

If Reader.FieldCount = 0 Then
   Throw New System.Exception("This shouldn't happen")
End If
@mgravell
Copy link
Owner

mgravell commented Jan 8, 2019 via email

@danj1980
Copy link
Author

danj1980 commented Jan 8, 2019

For background, here is how I'm using it...
I've got a function that takes a Linq2SQL DataContext and a Type, and submits the changes using SQLBulkCopy, instead of SubmitChanges().
Public Function PerformBulkInsert(DB As DataContext, TypeToInsert As Type)
As the function can be called with any TypeToInsert, I had to use a List(of Object) within the function to store the relevant objects from DB.GetChangeSet.Inserts that are the matching type.

I've since discovered that, since I'm passing in the Type of objects that the function should submit, I can use New FastMember.ObjectReader(GetType(TypeToInsert), Objects) as a solution.

What behaviour would you expect in this scenario? Object has zero public readable properties, etc...

Unless there is a case where ObjectReader would be successfully used with Object, I was expecting that Create<T>(IEnumerable<T> source, params string[] members) would throw a NotSupportedExpection if T is Object. Instead it returned an unusable Reader (unuseable in my case), so SqlBulkCopy.WriteToServer(Reader) silently made no SQL DB changes.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants