I get objects by
IEnumerable<ObjectStateEntry> om = context.ObjectStateManager.GetObjectStateEntries(System.Data.EntityState.Modified);
How can I get a List
of the objects with a type given by a string?
Type typ = Type.GetType("mytype");
var om2 = om.Select(s => s.Entity).OfType<typ>(); // does not work
Pass the List<String> as a parameter to the constructor of a new ArrayList<Object> . List<Object> objectList = new ArrayList<Object>(stringList); Any Collection can be passed as an argument to the constructor as long as its type extends the type of the ArrayList , as String extends Object .
Yes, it is absolutely fine to have an object contains list of object.
A list can be converted to a set object using Set constructor. The resultant set will eliminate any duplicate entry present in the list and will contains only the unique values.
What you are trying to do cannot be done statically: var
corresponds to the static type of the expression, while the type of your expression on the right is clearly non-static (it's IEnumerable<T>
, where T
is not known before the runtime).
This, however, is legal:
var om2 = om.Select(s => s.Entity).Where(v => typ.IsInstanceOfType(v));
This would produce an IEnumerable<ObjectStateEntry>
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With