Hi Folks
I'm using LINQ to Entities to interact with my SQL Server DB. I'd like to extend (add partial class bits) the generated partial entity classes and have a list of questions related to that. This is also my first investigation of using partial classes!
1) So far I have been looking at the code in myedmx.Designer.vb file (created by using the visual edmx creator thing) to see what is already generated for the partial class. Is there generally any other bits of these partials stored in any other files I might be missing?
2) If one of the auto generated partials is declared as below, in my new class file with the extending partial classes do I need to re-specify:
- the namespace
- the classes attributes
- the inheritance
Or is this taken care of by the fact of it being a partial of the same class? I.E. will a new partial automatically "share" its sibling's attributes and inheritance?
3) If I would like to add some business type logic in my new partial class, what is the best way to generically reference the context that the class is part of?
I.E. If I wanted a function in partial class myTableName to query another table within the same context, is there some way of replacing where we would normally directly reference a context such that a query might be able to reference its parent context?
E.G.
Or is there a better manner entirely of doing such?
EDIT: Thought I might give a little more info on Q3:
I have two tables "RackBay" and "Program". I have added a new member "AcProgramId" in my Public Partial Class RackBay.
When the user wants to assign an AcProgram to the RackBaythey pass an Id integer to the object as the parameter of a Public Sub
The Sub first checks some other added private members to see if the user is allowed to set the AcProgram at this time.
Then the Sub needs to A) confirm that the argument the user passed is a valid id - find the record with the same ID on the Program table
B) confirm the AC column of the found ID record on the Program table is true.
D) select the value from the ProgramName column of the found ID record in the Program table.
Normally I would of course be able to use a simple query such as: Dim AcProgramName = From q In myContext.Program Where q.Id = acIdArgument And q.Ac = True Select q.ProgramName.
But if I was to do this what would go in for "myContext"?
Or Maybe I would need to use the partial class to set up some kind of navigation property between the two tables instead?
I'm using LINQ to Entities to interact with my SQL Server DB. I'd like to extend (add partial class bits) the generated partial entity classes and have a list of questions related to that. This is also my first investigation of using partial classes!
1) So far I have been looking at the code in myedmx.Designer.vb file (created by using the visual edmx creator thing) to see what is already generated for the partial class. Is there generally any other bits of these partials stored in any other files I might be missing?
2) If one of the auto generated partials is declared as below, in my new class file with the extending partial classes do I need to re-specify:
- the namespace
- the classes attributes
- the inheritance
Or is this taken care of by the fact of it being a partial of the same class? I.E. will a new partial automatically "share" its sibling's attributes and inheritance?
VB Code:
' <EdmEntityTypeAttribute(NamespaceName:="mySqlDataModel", Name:="myTableName")> <Serializable()> <DataContractAttribute(IsReference:=True)> Public Partial Class myTableName Inherits EntityObject #Region "Factory Method" '.... #End Region #Region "Primitive Properties" '.... #End Region End Class
3) If I would like to add some business type logic in my new partial class, what is the best way to generically reference the context that the class is part of?
I.E. If I wanted a function in partial class myTableName to query another table within the same context, is there some way of replacing where we would normally directly reference a context such that a query might be able to reference its parent context?
E.G.
VB Code:
' Dim queryFromOtherTable = From q in Me.ParentContext.OtherTableName ...
EDIT: Thought I might give a little more info on Q3:
I have two tables "RackBay" and "Program". I have added a new member "AcProgramId" in my Public Partial Class RackBay.
When the user wants to assign an AcProgram to the RackBaythey pass an Id integer to the object as the parameter of a Public Sub
The Sub first checks some other added private members to see if the user is allowed to set the AcProgram at this time.
Then the Sub needs to A) confirm that the argument the user passed is a valid id - find the record with the same ID on the Program table
B) confirm the AC column of the found ID record on the Program table is true.
D) select the value from the ProgramName column of the found ID record in the Program table.
Normally I would of course be able to use a simple query such as: Dim AcProgramName = From q In myContext.Program Where q.Id = acIdArgument And q.Ac = True Select q.ProgramName.
But if I was to do this what would go in for "myContext"?
Or Maybe I would need to use the partial class to set up some kind of navigation property between the two tables instead?