Database Queries in MVC Model

后端 未结 2 969
不思量自难忘°
不思量自难忘° 2021-02-09 13:43

In a MVC project if I put LINQ queries in Model, is it against the MVC Pattern?

namespace DocLibrary.Models
{
    public class Auth         


        
2条回答
  •  佛祖请我去吃肉
    2021-02-09 14:08

    use like this

    internal IQueryable GetArmyList2()
        {
            //var lists = from list in db.Table1
                     //   select list;
    
            //return lists;
    
    
            var query = from Table1 in db.Table1
                        where Table1.Username.Equals("asik") & Table1.Password.Equals("asik")
                        select Table1;
    
            return query;
    
    
        }
    

    and controller code

    public ActionResult asik()
        {
            var armyList = cl.GetArmyList2();
            return View(armyList);
            // return View();
        }
    

提交回复
热议问题