So let's say I have an Person entity:
PERSON
ID
FirstName
LastName
SSN
LastModifiedDate
After this table exists in the database, and is part of my .edmx file, I usually create a partial class for the entity to use to perform some object-specific work. For example, with the Person entity I might have an UpdateLastModifiedDate() method which would simply set the value for the LastModifiedDate field to the present date and time for the selected object.
My question, however has to do with more "generic" methods, that don't relate to any specific object. For example, let's say I wanted to create a GetPersonBySSN() method which would accept a SSN and return the Person object with that SSN (if it exists). Where would I store this method?
I couldn't store it in the partial class (could I?) because I would have to do something odd like this:
Person myPerson = db.Person.where(u => u.ID = 12345);
Person myPerson2 = myPerson.GetPersonBySSN(123456789);
It just doens't make sense to do it this way.
Also, I am reluctant to create a second static class to store these "generic" methods (like maybe a PersonGenericMethods class) because it feels like I should be able to do this with only the main class, Person.
Where would you store these "generic" methods?
Edit: I am using ASP.NET MVC and would like recommendations on how to best build using this.
Aucun commentaire:
Enregistrer un commentaire