本文介绍了Model将objec返回给BLL的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述 您好! 步骤: 查看: ListCards.DataSource = BLL.Cards.GetListCards(); BLL: Hello!Be to steps:VIEW:ListCards.DataSource = BLL.Cards.GetListCards();BLL:public static class Cards { public static List<Cards.Model.Cards> GetListCards() { return DAL.Cards.GetCardsList(); }} DAL: DAL:public static class Cards { public static List<Cards.Model.Cards> GetCardsList() { var _db = new BioStarEntities(); //string param = ConfigurationSettings.AppSettings["SelectLikeParam"]; var query = from c in _db.TB_USER where c.sUserName.Contains("vizit") select new { c.nStart, c.nEnd, c.nUser, c.sTel, c.sUser, c.sUserID }; return query as List<Cards.Model.Cards>; } 必须检查,DAL和BLL的类是静态的。 在DAL,返回包含所选字段的对象,但是为什么它的数据在View(Datagridview)中为空?Must check, that Classes at DAL and BLL are Static.At DAL, returns object with selected fields, but why it data comes empty at View (Datagridview)?推荐答案 在DAL方法的return语句上放置一个断点并检查cast是否返回null。您可以在LINQ表达式中创建一个与您的类卡不同的匿名类型。Put a breakpoint on return statement of DAL method and check if casting returns null. You can creating an anonymous type in your LINQ expression which is not same as your class Cards. 这篇关于Model将objec返回给BLL的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! 11-02 15:03