Coder Social home page Coder Social logo

Comments (9)

ipvalverde avatar ipvalverde commented on May 16, 2024

Hi @xavave, thanks for noticing that one.
Unfortunately, the SimpleCollectionColumnDataExtractor creates a new instance of the collection type inside of it. So in this case, it would try to create an insurance of ICollection<TCollectionItem>, that is why you see that error.

I'm not on my computer at the moment, I'll try to give a look into it tomorrow on how else this can be done. If you have any suggestions, feel free to share as well.

from epplus.dataextractor.

xavave avatar xavave commented on May 16, 2024

I've added a constructor with ObservableCollection, it should fit my requirements

from epplus.dataextractor.

xavave avatar xavave commented on May 16, 2024

Awesome ! Thank you !
I will take a look at your code to understand how you have made it

from epplus.dataextractor.

ipvalverde avatar ipvalverde commented on May 16, 2024

You're welcome! Just released version 2.1.0 on Nuget with this feature

from epplus.dataextractor.

xavave avatar xavave commented on May 16, 2024

Hi Israel,
Can I use an observable Collection with this new implementation ?
I get an error :
public virtual ObservableCollection<Ingredient> FormulaIngredients { get => formulaIngredients; set => Set(ref formulaIngredients, value); }
error :
'Expression of type 'System.Collections.ObjectModel.Collection1[Formula.DAL.Model.Ingredient]' cannot be used for assignment to type 'System.Collections.ObjectModel.ObservableCollection1[Formula.DAL.Model.Ingredient]''

and
.WithCollectionProperty(p => p.FormulaIngredients,
1, "F", cfg => cfg
.WithProperty(ing => ing.TempImportId, "RM ID")
.WithProperty(ing => ing.MainTypeId, "RM type", FnConvertMainTypeName)
.WithProperty(ing => ing.Weight, "RM poids", fnParseDouble)
)

from epplus.dataextractor.

ipvalverde avatar ipvalverde commented on May 16, 2024

Could you check if your formulaIngredients is null?

If it is null, since ObservableCollection inherits from Collection, the overload used in the WithCollectionProperty is the Collection one and then the code tries to create a new instance of Collection and assign it to your property...

from epplus.dataextractor.

ipvalverde avatar ipvalverde commented on May 16, 2024

Nevermind, I was able to reproduce the issue, it is not related to the property being initialized or not. I should publish a fix by tomorrow.

from epplus.dataextractor.

ipvalverde avatar ipvalverde commented on May 16, 2024

Thanks for noticing that error @xavave. Unfortunately, in order to provide a proper fix, I introduced a breaking change on version 2.2.0.

TL;DR
For your case, of an initialized collection property that is not a List<T>, HashSet<T> or Collection<T>, you can use the new method: WithInitializedCollectionProperty instead of WithCollectionProperty.

Full story
If you are using the method WithCollectionProperty for a collection property that is not a List<T>, HashSet<T> or a Collection<T>, an exception will be thrown at runtime. In your case, since your property is of type ObservableCollection<T>, the overload that accepts a Collection<T> is picked and this generates an error.
What should happen in this case, is that the overload with ICollection<T>, for initialized collection properties, should be picked instead. To prevent the necessity of specifying generic types when calling the method, now the WithCollectionProperty overloads that accept ICollection<T> are obsolete, new methods were created specifically for the ICollection<T>: WithInitializedCollectionProperty

from epplus.dataextractor.

xavave avatar xavave commented on May 16, 2024

thank you, it works with WithInitializedCollectionProperty

from epplus.dataextractor.

Related Issues (17)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.