c# - How to store a recursive model with entity framework 5.0 -
I'm new to the organization and am trying to store the following models in a database. I have seen the tutorial I want to store the code using the following model code first, but I could not archive this recursive structure. It only stores the initial root node.
My model looks like this:
Public intangible class node: INode {public int nodeId {get; Set; } Public node () {nodes = new list & lt; INode & gt; (); } Public Inode ParentNode {get; Set; } Public listing & lt; INode & gt; Nodes {receive; Private set; } Public string name {get; Set; }}
and the derived sub type:
public class module: node, emode {} public square location: node, redemption {}
/>Interfaces are:
Public Interface INode {INode ParentNode {get; Set; } List & lt; INode & gt; Nodes {receive; } String name {get; Set; }} Public Interface Impulse: Inode {} Public Interface Illocation: Inode {}
This is my DbCTintact:
Public class SqlEntityContext: DbContext {public DbSet & Lt; Node & gt; Nodes {receive; Set; }}
Then I create a model of a dual module node with two locale nodes. If I try to store it with this code
(var db = new SqlEntityContext ()) {db.SqlSystemNodes.Add (root as SqlSystemNode); Db.SaveChanges (); }
The root node is stored in the database only, I have tried to give my subkey type its key, but without success How do I store this model in database, any ideas? Is this possible?
Did you define in relation to parents in your DB reference initiator.
You need STH to START like this:
modelbuilder.Entity < Node & gt; () .home (o = o.o.odes) .onObest () // Mandatory () .Map (M => M.Mamke ("ParentNoode ID");
Comments
Post a Comment