我想初始化列表,并根据某些值使此列表具有一种特殊的类型,这是我创建的模型。我不知道我是否解释得很好-我的代码在下面
public static List<someModeltypeAorBorC> SomeMethod()
{
var list = new List<dynamic>();
if (Val == "A")
{
List<ModelA> list = new List<ModelA>();
}
else if (Val == "B")
{
List<ModelB> list = new List<ModelB>();
}
else if (Val == "C")
{
List<ModelC> list = new List<ModelC>();
}
}
我想在范围之外初始化列表,以便可以在下一步中使用。您也可以看到,我必须返回此列表。可能吗?我将不胜感激!
答案 0 :(得分:0)
您可以尝试:
SELECT customer_brandids.brand_id, brands.brand_id, customer_brandids.customer_id, brands.brand_name
FROM
(SELECT customer_receipts.receipt_id, receipt_item_details1.receipt_id, customer_receipts.customer_id, receipt_item_details1.brand_id
FROM
(SELECT receipts.customer_id, customers.customer_id, receipts.receipt_id
FROM receipts
INNER JOIN customers
ON receipts.customer_id = customers.customer_id) AS customer_receipts
INNER JOIN receipt_item_details1
ON customer_receipts.receipt_id = receipt_item_details1.receipt_id) AS customer_brandids
INNER JOIN brands
ON customer_brandids.brand_id = brands.brand_id
答案 1 :(得分:0)
谢谢大家的回答。我最后要做的是创建其他Model A.B和C继承的Model类。在方法中,我添加了行
List<Model> list = new List<Model>();
我返回List,当我需要访问下层阶级的属性时,我正在使用
List<Model> obj = List<Model>;
obj = SomeMethod() //which return object of ModelA.B or C
((ModelA)obj).PropoertyOfModelA // reach the property specified model