[英]Nhibernate and Query example
class Customer
{
public int ID { get; set; }
public string Name { get; set; }
}
class Order
{
public int ID { get; set; }
public string Product { get; set; }
}
var customers = new Customer[]
{
new Customer{ID = 5, Name = "Sam"},
new Customer{ID = 6, Name = "Dave"},
new Customer{ID = 7, Name = "Julia"},
new Customer{ID = 8, Name = "Sue"}
};
var orders = new Order[]
{
new Order{ID = 5, Product = "Book"},
new Order{ID = 6, Product = "Game"},
new Order{ID = 7, Product = "Computer"},
new Order{ID = 8, Product = "Shirt"}
};
IEnumerable<Object> query =
from c in customers
join o in orders on c.ID equals o.ID
select new { c.Name, o.Product };
IList<Object> AA = query.ToList<Object>();
This one return new object that is shown into picture [But I want to access this object as customer and order how can I get data as 'customerObject.propertyName and order.propertyName" instead of getting array with string. Can I get list of data with two object like customer and order object so I can access those data using that object] It returns aa[0] = {name=" sam ", product=" Book"}
but I want something like aa[0] = {Customer.Name , Order.product }
[1] 此对象返回显示在图片中的新对象[但是我想以客户身份访问此对象并订购如何以'customerObject.propertyName和order.propertyName'的形式获取数据,而不是获取带有字符串的数组。我可以获取数据列表有两个对象,例如客户和订单对象,因此我可以使用该对象访问这些数据]它
returns aa[0] = {name=" sam ", product=" Book"}
但是我想要aa[0] = {Customer.Name , Order.product }
[1]
You could try to return the mapped objects. 您可以尝试返回映射的对象。 Considering you have your mapped entities, try something like this:
考虑到您有映射的实体,请尝试如下操作:
var result = (from c in customers
join o in orders on c.ID equals o.ID
select new{ Customer = c, Product = o.Product })
.ToList();
Then you can access you result
object as a collection of anonymous objects where you have the Customer
property and Product
which has your entities. 然后,您可以将
result
对象作为匿名对象的集合来访问,其中您具有Customer
属性,而Product
具有您的实体。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.