Home > Net >  EF Core mapping relation and the data (such as urgent master)
EF Core mapping relation and the data (such as urgent master)

Time:10-07

I am now ready to use EF Core fetch the data from an existing database, there are three tables:

One, JobHeader can contain multiple JobOperation, associated key is JobNum, also a JobOperation, can contain multiple OprTransactions, associated key is JobNum + OpCode

How do I use EF Core to define the mapping relations and values?

Public class JobHeader
{
[Key]
Public string JobNum {get; The set; }
Public string PartNum {get; The set; }
}

Public class JobOperation
{
[Key]
Public int Id {get; The set; }
Public string JobNum {get; The set; }
Public string OpCode {get; The set; }

}

Public class OprTransactions
{
[Key]
Public int Id {get; The set; }
Public string JobNum {get; The set; }
Public string OpCode {get; The set; }
Public string TransType {get; The set; }
}

hope value content is as follows:

{
"JobNum" : "000025172-0009,"
"PartNum" : "CIB kt - 75-00024 - A",
"JobOperation" : [
{
"JobNum" : "000025172-0009,"
"OpCode" : "NF01,"
"OprTransactions" : [
{
"Id" : 1,
"JobNum" : "000025172-0009,"
"OpCode" : "NF01,"
"TransType" : "OPRSTART,"
},
{
"Id" : 2,
"JobNum" : "000025172-0009,"
"OpCode" : "NF01,"
"TransType" : "OPREND,"
}
]
},
{
"JobNum" : "000025172-0009,"
"OpCode" : "NF34,"
"OprTransactions" : [
{
"Id" : 3,
"JobNum" : "000025172-0009,"
"OpCode" : "NF34,"
"TransType" : "OPRSTART,"
}
]
}
]
}

CodePudding user response:

Waiting for player

Wait until the answer is "stick!

CodePudding user response:

EF is not particularly familiar with, but I think in the DbContext Entity concept, you can use the EntityConnection and EntityCommand TO look at, then rewrite CreatingModel and CreatingTable, you can LINQ TO SQL way TO serialize the see,

Because writing is less, also don't like this way, so seldom used at ordinary times,

Recommend you a post under https://www.cnblogs.com/libingql/p/4052906.html

CodePudding user response:

Format I really don't like this way, although the fast, for readability,

CodePudding user response:

Thank you for your reply, feeling should not complicated, just normal with less EF Core...

CodePudding user response:

You this simple
 
Public class JobHeader
{
[Key]
Public string JobNum {get; The set; }
Public string PartNum {get; The set; }
Public virtual List JobOperations {get; The set; }
}

Public class JobOperation
{
[Key]
Public int Id {get; The set; }
Public string JobNum {get; The set; }
Public string OpCode {get; The set; }
Public virtual List OprTransactions {get; The set; }
}

Public class OprTransactions
{
[Key]
Public int Id {get; The set; }
Public string JobNum {get; The set; }
Public string OpCode {get; The set; }
Public string TransType {get; The set; }
}

//then you finally make JobHeader toJson (); Is the result you above the

CodePudding user response:

You just define the mapping relation, there is no tell how to get data oh,,,

CodePudding user response:

EF has a special design called navigation attribute,
  •  Tags:  
  • LINQ
  • Related