( These smaller contexts follow a pattern critical to Domain Driven Design called Bounded Contexts). If you have sub areas in your mvc project which have specific business logic, you can split it into multiple DbContext. I am also using the concept of Bounded DbContext by which we can create separate DbContext for group of Entities and keep them clean and grouped. I am building dynamic connection string at runtime for multiple database operations in one application.
I have following codes in my CompanyDbContext.cs class for my MVC 3 C# project. Use object as return type as mentioned below to avoid that error, so it lets you select specific columns from SQl server table. Reason: You can’t use Anonymous return type in C# Model class, so it throws an error. But when you do same query in C# class method of return type IQueryable() you get error as said before. When you try query in LINQ Pad you get the Correct Result with Anonymous return type which doesn’t do anything. Var getStudents = (from b in Students orderby b.Name You can get the list of Students with their Name, Phone and Email by following LINQ query. When you try to select specific column via LINQ queries or Lamda Expression in MVC C# class, you might see above error.
Cannot implicitly convert type ‘’ to ‘’.Īn explicit conversion exists (are you missing a cast?)