我如何能遍历一个C#的IEnumerable在Matlab? [英] How can I iterate over a C# IEnumerable in Matlab?

查看:139
本文介绍了我如何能遍历一个C#的IEnumerable在Matlab?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一些LINQ到SQL code在C#中,我试着用Matlab 2010年b访问。如果我的LINQ code返回单个项目例如,我可以没有问题访问Matlab的所有属性:

I have some Linq to SQL code in C# that I'm trying to access using Matlab 2010b. If my Linq code returns a single item instance, I can access all the properties without problem in Matlab:

dal = Data.PeopleRepository
person = dal.QueryPersonById(1)
person.Name

ans = 

John Smith

但是,如果我叫一个LINQ查询,返回一个IQueryable集合(实际上是System.Data.Linq.Table类),我挣扎着爬在人的实例里面!列表

But if I call a Linq query that returns an IQueryable collection (actually a System.Data.Linq.Table class), I'm struggling to get at the list of Person instances inside!

people = dal.QueryAllPeople()

people = 

System.Data.Linq.Table<Data.Person> handle
Package: System.Data.Linq
Properties:
   Context: [1x1 Data.PeopleRepository]
   IsReadOnly: 0

我试着使用GetEnumerator方法的人转换为一个IEnumerable,但我还是不能让在里面的真人实例。 (我知道,由于后期的评估值可能没有实际从数据库中检索过Aarggh!)任何指针AP preciated,并道歉,如果这是不明确 - 这是我的第一个计算器问题...

I've tried converting to an IEnumerable using the GetEnumerator method on people, but I still can't get at the actual Person instances inside. (I'm aware that due to late evaluation the values may not yet actually be retrieved from the database too! Aarggh!) Any pointers appreciated, and apologies if this is unclear - it's my first StackOverflow question...

推荐答案

我只工作Matlab和C#的其他方式(从C#调用Matlab的),但它看起来对我来说,问题是你有一个IQueryable实例而不是在你的code一个IEnumerable

I've only worked Matlab and C# the other way around (calling Matlab from C#) but it looks to me like the problem is that you have an IQueryable instance instead of an IEnumerable in your code.

尝试调用人= dal.QueryAllPeople()了ToList()人= dal.QueryAllPeople.ToArray() - 这将导致执行查询 - 然后将数据有望提供内部Matlab的。

Try calling people = dal.QueryAllPeople().ToList() or people = dal.QueryAllPeople.ToArray() - these will cause a query to be executed - and the data will then hopefully be available inside Matlab.

更新 - 因为扩展方法是一个没有没有......发生什么事,如果你尝试:

Update - since extension methods are a no-no... what happens if you try:

myEnumerator = dal.QueryAllPeople().GetEnumerator()
myEnumerator.MoveNext()
firstItem = myEnumerator.Current
firstItem =

myEnumerator.MoveNext()
secondItem = myEnumerator.Current
secondItem =

这篇关于我如何能遍历一个C#的IEnumerable在Matlab?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆