Click here to Skip to main content
15,306,376 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Hi All,

I have generated model from Database(Database first approach).
Then I converted a primary key columns into Identity(1,1). Now without refreshing the Model from database i would like to insert a record(e.g. db.Addobject(obj)). I mean i want to edit the edmx.cs file to accommodate this Identity field in Database.

Please help.
Posted
Updated 5-Sep-17 23:26pm
Comments
David_Wimbley 24-Mar-14 0:59am
   
why would you not want to refresh the model in your entities? Its simple to just to Update Model From Database and this would solve your problem.

What is the name of your Identity column for one...that would help. It would really just be easier to do update model from database.
Prasad Avunoori 24-Mar-14 2:23am
   
Thank you, David for your reply.

As you said, when i refresh from the Database I lost Data Annotations e.g. [DisplayName("Employee Name")] for EmployeeName property.
Amitava Bag (Kolkata) 24-Mar-14 5:08am
   
Please make a partial class and transfer all custom data annotation to there. Then update the .edmx file without any worry.
David_Wimbley 24-Mar-14 15:03pm
   
I agree with amitava...can do partial class or create ViewModels for your entities if you wanted
Prasad Avunoori 24-Mar-14 23:13pm
   
Thank you, Amitava for your thought any online example is great for me.
Prasad Avunoori 24-Mar-14 23:46pm
   
I got the e.g. here. http://themonitoringguy.com/tips-tricks/validating-microsoft-entity-framework-objects-c-mvc/#comment-171

Thank you for your suggestion, Amitava.
Amitava Bag (Kolkata) 25-Mar-14 2:06am
   
Welcome...

1 solution

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

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900