I've seen a lot of these types of questions on here but they are either unanswered, not quite the same question that I am asking or the detail I need.
I have included a screenshot of my project below for a high-level reference view of things.
Sample.Data.Model
that contains an edmx file of my database-first model. Sample.Data.Entities
. Sample.Data.Entities
project in my Sample.Data.Model
project and fixed all the usings so my project builds successfully.PartialClasses
folder in the Sample.Data.Entities
project for my partial classes.And then this is where I get lost. In smaller (non n-tier projects) my edmx file and partial classes where in the same project so I could just add my class object related methods in my partial class files like this:
namespace Sample.Data.Entities
{
public partial class User
{
public string FullName
{
get
{
return string.Format("{0} {1}", this.FirstName, this.LastName);
}
}
}
public User GetUser(int userID)
{
using (var dc = new ProntoEntities())
{
return (from u in dc.Users where u.ID == userID select u).SingleOrDefault();
}
}
}
And then in MVC project I could just do something like this...
User user = new User();
user = user.GetUser(1);
OR
User user = new User();
user.FirstName = "John";
user.LastName = "Smith";
user.Update();
However, I can't do that in this current setup because the partial classes know nothing about the Entities.
So, my question is, where in my current setup do I put the "queries" for data?
Also, if I'm going to make "ViewModels" for my MVC project, where should those go? I would usually put those in the same project as my partial classes and edmx file as well.
So, my question is, where in my current setup do I put the "queries" for data?
I think you should use the magical Repository Pattern.
For example: http://www.remondo.net/repository-pattern-example-csharp/
Also, if I'm going to make "ViewModels" for my MVC project, where should those go?
Since viewmodel contain data what are connected to their views, i believe you don't need to put together with the Entities or their partial classes. If i were you, i just put to the Model folder in your MVC project.