I've googled the heck out of this all day, and haven't found an answer. This seems like such a simple topic that it would be somewhere, but maybe I'm searching wrong... but forgive me if this is a duplicate...
Currently, in the project, all data-access level objects are initialized by a method in a partial class. So it's created, with null values across the board, and then we call a custom get method on it, which contains some variant of:
public MyObject GetMyObjectByID(int myPrimaryKey)
using (var db = new myContext())
MyObject myObject = new MyObject();
myObject = db.MyObjects.Find(myObject.primaryKey = myPrimaryKey);
...and assign the MyObject created to the initial object.
So that works... but it seems like a lot of run around. If the find() is so simple, and works so smoothly off the primary key, shouldn't there be a way to put that in a constructor? Just create the object with
MyObject myObject = New MyObject(MyPrimaryKey);
Like I said, I've googled it all morning, looking for constructors for ef6, and constructors with primary key... can't seem to find what I'm sure is an obvious answer...