|
-
Apr 24th, 2013, 11:21 PM
#1
Thread Starter
Fanatic Member
save model from another model
how can i save my model to another same model ?
Code:
[HttpPost]
public ActionResult Create(Employee employee)
{
if (ModelState.IsValid)
{
db.Employees.Add(employee);
db.Employees_log.Add(employee); ===> error: "unable to update entityset because it has a definingquery and no insertfunction"
db.SaveChanges();
}
}
I basically wanted to save two models at the same time.
Last edited by VBKNIGHT; Apr 25th, 2013 at 01:08 AM.
If a post has helped you then Please Rate it!
-
Apr 25th, 2013, 03:56 PM
#2
Re: save model from another model
When a table doesn't have a primary key it is treated as a view. Since it's treated as a view it'll show up in the defining query section of the edmx. Try following the example here to fix it: http://blogs.msdn.com/b/alexj/archiv...ble-views.aspx
This pattern in common to all great programmers I know: they're not experts in something as much as experts in becoming experts in something.
The best programming advice I ever got was to spend my entire career becoming educable. And I suggest you do the same.
-
Apr 25th, 2013, 11:17 PM
#3
Thread Starter
Fanatic Member
Re: save model from another model
well after spending so much time with it i finally get it to save the records yes it's true you need to have an key in your table and remove the defining query.
my question is why is my edmx file the (model class specifically) change to default? even if i edited the file and put attributes on each field using visual studio 2012.
is there a correct tool or way of editing the edmx file? should it only be updated once then manually change it if there's an need to?
If a post has helped you then Please Rate it!
-
Apr 26th, 2013, 12:41 AM
#4
Re: save model from another model
 Originally Posted by VBKNIGHT
well after spending so much time with it i finally get it to save the records yes it's true you need to have an key in your table and remove the defining query.
my question is why is my edmx file the (model class specifically) change to default? even if i edited the file and put attributes on each field using visual studio 2012.
is there a correct tool or way of editing the edmx file? should it only be updated once then manually change it if there's an need to?
If you make changes to the database then you open the model in the designer, right-click the empty space and select Update From Data Source or the like. That will re-run the original wizard and your updated schema will be imported. That said, some things will not change, e.g. if you have renamed a column then the new name will be added but the old name will remain. Persoanlly, I often just delete entities for tables that have changed to ensure that there's no rubbish left behind. In fact, you can simply delete the whole model and regenerate it from scratch. If the names are the same then all your existing will just work.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|