In an MVC project, if I put LINQ queries in Model , is this against the MVC pattern?
namespace DocLibrary.Models { public class Author { private DocLibraryContext db = new DocLibraryContext(); [Key] public Int32 AuthorId { get; set; } [StringLength(20)] public String Name { get; set; } .. public string GetNameById(int AuthorId) { var query = from a in db.Author where a.AuthorId == AuthorId select a.Name; return query.FirstOrDefault(); } public Author GetAuthorById(int AuthorId) { var query = from a in db.Author where a.AuthorId.Equals(AuthorId) select a; return query.FirstOrDefault(); } }
Or do I need to move these methods ( GetNameById , GetAuthorById ) to the controller?
oop asp.net-mvc
Nalaka526
source share