Home > Net >  Help EF datafirst mysql many-to-many relationship to add the following code
Help EF datafirst mysql many-to-many relationship to add the following code

Time:05-16

 
Nh3Entities1 db=new nh3Entities1 ();
Var ds=db. SetVar _role=ds. The Find (1);

If (_role. Sys_menuaction. Count (m=& gt; M. id==5)==0)
{

Sys_menuaction _sm=new sys_menuaction
{
Fid=5
};
_role. Sys_menuaction. Add (_sm);
The Entry (_sm). State=System. Data. The Entity. The EntityState. Unchanged;

The SaveChanges ();

}


To produce three SQL
 
SELECT
` Extent1 `. ` fid `,
` Extent1 `. ` Name `,
` Extent1 `. ` CreateUser `,
` Extent1 `. ` UpdateUser `,
` Extent1 `. ` CreateTime `,
` Extent1 `. ` UpdateTime `,
` Extent1 `. ` Remark `,
` Extent1 `. ` IP `,
MAC ` ` Extent1 `. `
The FROM ` sys_role ` AS ` Extent1 `
WHERE ` Extent1 `. ` fid `=1 LIMIT 2

SELECT
` Extent2 `. ` fid `,
` Extent2 `. ` MenuTree_Id `,
` Extent2 `. ` Action_Id `
The FROM (SELECT
` role_menu_action `. ` MenuAction `,
` role_menu_action `. ` Role `
The FROM ` role_menu_action ` AS ` role_menu_action `) AS ` Extent1 ` INNER JOIN ` sys_menuaction ` AS ` Extent2 ` ON ` Extent1 `. ` MenuAction `=` Extent2 `. ` fid `
WHERE ` Extent1 `. ` Role `=1

INSERT INTO (SELECT
` role_menu_action `. ` MenuAction `,
` role_menu_action `. ` Role `
The FROM ` role_menu_action ` AS ` role_menu_action `) (
` MenuAction `,
` Role `) VALUES (
5,
1)


Regardless of how it produces query SQL, mainly is the INSERT INTO that execution is not successful, how to write

CodePudding user response:

The combination of EF + mysql so wonderful work...

I'm not so used, but ef + is essentially a many-to-many relationship I is to define a class specifically responsible for the many-to-many entity type, it is better to write a linq
  •  Tags:  
  • C#
  • Related