Entity Framework ObjectSet in Powershell -
i've created dll in visual studio holds entity framework objectcontext
. i'm trying access various objectset
s powershell. i'm doing because have xml files i'm pulling web service , i'd use powershell's xml features (automatic property generation, non-fatal $null evaluation) map incoming xml values entities instead of having use c# xml classes. powershell script data loader.
i able create , instantiate objectcontext fine. can see properties using $myobjectcontext | get-member -membertype property
. however, i'm having trouble understanding when items returned queries objectset.
i know in linq-to-entities, there lazy loading , objects loaded when collection enumerated. i've tried calling extenion methods explicity, looks powershell doesn't provide lambda expression support.
here's question. how know when queries going explicitly enumerated? example, here's 1 of properties (defined objectset
). <vehicletype
> vehicletypes { get; }
ps> $myobjectcontext.vehicletypes
produces following error, i'll label (theerror) future reference:
format-default : exception has been thrown target of invocation. + categoryinfo : not specified: (:) [format-default], targetinvocationexception + fullyqualifiederrorid : system.reflection.targetinvocationexception
but, ps> $myobjectcontext.vehicletypes | select-object vehicletypeid
produces correct output (a table of vehicletypeids)
however, ps> $myobjectcontext.vehicletypes | select-object *
gives theerror described above.
ps> $myobjectcontext.vehicletypes | sort-object
seems enumerate collection, understandable since needs @ elements compare them.
i should note after collection enumerated once, calling ps> $myobjectcontext.vehicletypes
not give theerror above - display collection you'd except. weird, think has lazy loading (which why mentioned above).
can else confirm/explain behavior me, , maybe give me pointers on best practices using entity framework powershell?
also, if ps> $myobjectcontext.vehicletypes | where-object {$_.vehicletypeid -eq $vehicletypeid}
going smart enough execute query server side, or going fetch records db , return 1 i'm looking for. if situation latter, think might stuck using c# (with not-so-friendly xml syntax) data access.
i can tell enumeration performed code: ps> $myobjectcontext.vehicletypes | where-object {$_.vehicletypeid -eq $vehicletypeid}
client-side.
if want perform native filtering, you'll need create cmdlet access data, or provider supports native filters.
Comments
Post a Comment