从数据库对象中检索列表 [英] Retrieve list from object in Database

查看:135
本文介绍了从数据库对象中检索列表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我要发使用asp.net包含在数据库名称列表

I want to send a list of names contained in a Database using asp.net

这是我的两个对象:

public class Shop
{
    public int ID { get; set; }
    public string Country { get; set; }
    public List<Item> Items{ get; set; }
}

public class Item
{
    public int ID { get; set; }
    public string Name { get; set; }
}

我想以检索项的列表以设置一个get控制器。
我做了这样的事情:

I want to set a get controller in order to retrieve a list of items. I did something like this:

 public IEnumerable<Item> Get(int id)
    {

        var items= new List<Item>();
        var shop= new Shop();

        using (var systemDB = new ShopsDB())
        {
                            it = systemDB.Shops.Where(s => s.ID == id).FirstOrDefault<Shop>();
                            items = it.Items;
        }   

            return items;

    }

这回&LT; ArrayOfItem我:无=真/&GT;
我想获得项目的完整列表,一店(例如,具有ID店= 1)

This return <ArrayOfItem i:nil="true"/>. I want to get the complete list of Items for one shop (e.g. shop with ID=1)

推荐答案

我解决了修改Item对象:

I solved modifying the Item object:

public class Shop
{
    public int ID { get; set; }
    public string Country { get; set; }
    public List<Item> Items{ get; set; }
}

public class Item
{
    public int ID { get; set; }
    public string Name { get; set; }
    public int ShopID { get; set; }
}

和设置查询选择ShopID

And set a query to select the ShopID

这篇关于从数据库对象中检索列表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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