last day (15 days later) » 

11:33 PM
1
Q: EntityFramework 6.0.0.0 reads data, but it is not inserting

StepUpI've created a Service-based Database folderName->Add New Item->Data->Service-based Database file into WPF application. Then I've used Database First approach and have created the PersonsModel.edmx file. These operations are executed perfectly. The reading of data works okay: using (PersonDBEnt...

 
L J
What is the SQL query EF is generating when you run the Add? Check Immediate Window in VS.
 
@HüseyinBurakKaradag please, see updated section of my question
 
L J
If you can get the query from your IDE (stackoverflow.com/a/20751723/6830901) and run it against your DB it would be useful.
 
@LJ please, see my updated question with what SQL query is run and its result.
 
L J
We might need to tell the EF that the context is modified. Could you please try with - EntityState.Modified on the entity state?
 
11:33 PM
@LJ nothing added. I've updated my question about what I've tried.
 
L J
Can we try Attach ; db.Departament.Attach(dep) as we are inserting a new entry; Apologies for keeping you long as it is taking time to understand the underlying logic.
 
@LJ it is okay:). But db.Departament.Attach(dep); is not inserting data.
 
L J
It will attach to the object and on SaveChanges it should be reflected on the DB. Is it not?
 
oops, sorry, but what do you mean?
are you here?
 
L J
Here. show me the db schema please. The virtuals are bit intriguing and not sure they are well constructed
 
11:35 PM
what is schema?:)
db schema
 
L J
Department
 
public partial class Departament
{
public Departament()
{
this.Person = new HashSet<Person>();
}

[Key]
[DatabaseGenerated(DatabaseGeneratedOption.Identity)]
public int IdDep { get; set; }
public string DepName { get; set; }

public virtual ICollection<Person> Person { get; set; }
}
 
L J
and how it looks in SQL?
Foreign keys
You might latter change the type of Departament to Department
*typo
Person object is in Department and we should make sure that it is constructed as well during SavingChanges
 
CREATE TABLE [dbo].[Departament] (
[IdDep] INT IDENTITY (1, 1) NOT NULL,
[DepName] NVARCHAR (100) NULL,
PRIMARY KEY CLUSTERED ([IdDep] ASC)
);
and Person table
CREATE TABLE [dbo].[Person] (
[IdPerson] INT IDENTITY (1, 1) NOT NULL,
[Name] NVARCHAR (100) NOT NULL,
[Surname] NVARCHAR (100) NOT NULL,
[Fk_IdBureau] INT NOT NULL,
[Fk_IdDep] INT NOT NULL,
PRIMARY KEY CLUSTERED ([IdPerson] ASC),
FOREIGN KEY ([Fk_IdBureau]) REFERENCES [dbo].[Bureau] ([IdBureau]),
FOREIGN KEY ([Fk_IdDep]) REFERENCES [dbo].[Departament] ([IdDep])
);
 
L J
EF version?
 
11:39 PM
EF 6.0.0.0
could you pull my project from github?:)
be very kind:)
 
L J
will do..
 
the last changes are applied to this project.
Thank you for pulling:)
 
L J
give me a few please
let me pull out and check it out
 
how can I do it?
it is possible to download the project and test it at your machine
 
L J
Yes, I am looking at it now
 
11:51 PM
thanks
 
L J
Are you hitting catch? if so with what excepton?
 
no hitting catch
no exceptions
just all is ok
have you tried the code?
 
L J
yup, getting blocked at exception
 

  last day (15 days later) »