Instead of having an add() method in the repository, I would like to overload the += operator so that the expression
_repository += myModel;
will insert myModel into the database(after i submit changes)
I know that the objects of different type cannot be used in operator overloading. Still want to know if there is some alternate ways to accomplish this
Any help?
I would strongly, strongly urge you not to do this even if you can. It goes against how operator overloading is meant to be used – what would you return from your operator? A new “clone” of the repository, or just
this?A generic method is the way to go here. Just say “no” to overusing operator overloading.