TECHNOLOGIES
FORUMS
JOBS
BOOKS
EVENTS
INTERVIEWS
Live
MORE
LEARN
Training
CAREER
MEMBERS
VIDEOS
NEWS
BLOGS
Sign Up
Login
No unread comment.
View All Comments
No unread message.
View All Messages
No unread notification.
View All Notifications
Answers
Post
An Article
A Blog
A News
A Video
An EBook
An Interview Question
Ask Question
Forums
Monthly Leaders
Forum guidelines
Adnan Okko
NA
19
3.3k
Update tables with relations from ViewModel (EF)
Mar 22 2018 7:37 AM
I have the following entities:
BIEntities db =
new
BIEntities();
public
class
SALES
{
public
int
IDs {
get
;
set
;}
public
string
product {
get
;
set
; }
ICollection<COUNTRIES> COUNTRIES {
get
;
set
; }
ICollection<PRICES> PRICES {
get
;
set
; }
}
public
class
COUNTRIES
{
public
int
IDc {
get
;
set
; }
public
string
country {
get
;
set
; }
public
virtual
SALES SALES {
get
;
set
; }
}
public
class
PRICES
{
public
int
IDp {
get
;
set
; }
public
string
price {
get
;
set
; }
public
string
strength {
get
;
set
; }
public
virtual
SALES SALES {
get
;
set
; }
}
And a ViewModel:
public
class
myViewModel
{
public
int
ID {
get
;
set
; }
public
string
product {
get
;
set
; }
List<
string
> country {
get
;
set
; }
List<
string
> price {
get
;
set
; }
List<
string
> strength {
get
;
set
; }
}
I am trying to update (edit) all entities from myViewModel:
[HttpPost]
[ValidateAntiForgeryToken]
public
ActionResult Edit(
int
id, FormCollection collection, myViewModel myModel)
{
SALES sUpdate = db.SALES.FirstOrDefault(s => s.IDs == myModel.ID);
if
(sUpdate !=
null
)
{
db.Entry(sUpdate).CurrentValues.SetValues(myModel);
db.SaveChanges();
}
return
RedirectToAction(
"Index"
);
}
I am getting this exception:
"System.InvalidOperationException: The view 'Validation failed for one or more entities. See 'EntityValidationErrors' property for more details.' or its master was not found or no view engine supports the searched locations."
Is this method correct? what other methods can I use to update the tables?
Reply
Answers (
6
)
Stored Procedure
how Streaming or buffer related to json or xml