Insert multiple records issue (linq EF)?

It looks like the issue is you are only setting the FK id (IDRepre, IDBanco). Usually when setting references in EF you use the entire object (cuenta. Credito = cred;) Credito cred = new Credito() { Producto = credito.

Producto, Tipo = credito. Tipo, Status = credito. Status, Cantidad = credito.

Monto_prestamo, TasaInteres = credito. Tasa_interes, Plazo = credito. Plazo, Periodo = credito.

Periodo, FechaInicio = credito. Fecha_inicio }; Cuentas cuenta = new Cuentas() { IDCredito = credito. IdCredito, IDBanco = credito.

IdBanco }; cred.Cuentas. Add(cuenta); ... (more mapping code here) context.credito. AddObject(cred); context.SaveChanges() You should only need to do "AddObject" for the parent object if the children are set correctly.

It looks like the issue is you are only setting the FK id (IDRepre, IDBanco). Usually when setting references in EF you use the entire object (cuenta. Credito = cred;).

Credito cred = new Credito() { Producto = credito. Producto, Tipo = credito. Tipo, Status = credito.

Status, Cantidad = credito. Monto_prestamo, TasaInteres = credito. Tasa_interes, Plazo = credito.

Plazo, Periodo = credito. Periodo, FechaInicio = credito. Fecha_inicio }; Cuentas cuenta = new Cuentas() { IDCredito = credito.

IdCredito, IDBanco = credito. IdBanco }; cred.Cuentas. Add(cuenta); ... (more mapping code here) context.credito.

AddObject(cred); context.SaveChanges(); You should only need to do "AddObject" for the parent object if the children are set correctly.

In fact i'm setting reference for all children except for "agrupaciones" which depends on "grupo" and "acreditados" that's why i'm adding "agrupaciones" object after "acreditados" and "grupos". If I comment "context.agrupaciones. AddObject(AgregaAgrupacion(i, credito));" line I get no problems – Jorge Zapata Oct 14 at 22:37 I would change that line to gpo.Agrupaciones.

Add(AgregaAgrupacion(i, credito)); This gives it context to the grupos object is it related to. – Gary. S Oct 14 at 22:48 If I get it right I should code the following: context.creditos.

AddObject(cred);cred. Bancos_credito. Add(cuenta); for (int I = 0; I Total_plazo; i++) cred.amortizaciones.

Add(AgregaAmortizacion(ref fechaPago, i, credito)); context.grupos. AddObject(gpo); for (int I = 0; I AddObject(AgregaAcreditado(i, credito)); gpo.agrupaciones. Add(AgregaAgrupacion(i, credito)); } – Jorge Zapata Oct 14 at 23:20 creditos, acreditados and grupos are parent tables, however 'acreditados' depends on 'creditos'.

How I should the framework work on this? – Jorge Zapata Oct 14 at 23:23 In that case you can set the relation the other way: acreditados. Creditos = cred; acreditados.

Grupos = gpo; where acreditados is a new instance of the entity type. – Gary. S Oct 147 at 0:15.

... SQL SERVER – Insert Multiple Records Using One Insert Statement – Use of UNION ALL Insert multiple records using UNION clause. Every one of you r experts. It needs to insert 100 rows starting from 1 to 100 into the Reference field.

Thanq for the above solution which was very useful to me.(About insertion of multiple values at single instance through query). I am happy to get the code for inserting multiple records using one INSERT statement. Special thanks goes to Pinal Dave.

Nice solution, thanks for sharing. I am inserting multiple records in to a table through . With each insertion I have to increment the recid field with 1.

Select (max(recid) + 1), …. This is working for only 1record insertion. If I insert more than 1 record then the recid value is not getting incremented for each record I insert.

So, Can anyone give a solution for this? I want to insert a new row (5,’e') in between 2 & 3. I want to insert a 2 new rows (6,’f’ )& (7,’g’ ) at a time into a table at position above 1 & below 4.

Can we do like this………. I am new to this and I need to create a table with 1,000,000 entries wherein it starts at 000000001 and so on.

I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.

Related Questions