0

I have a model that I'm loading into a table within a form. The records are retrieved from an Oracle DB using EF6 and loaded into the model. I also want the user to be able to select records to delete from the database via a checkbox in each row in the form.

The function to retrieve the Attendees:

public List<WebinarAttendeesList> getAttendees(string webinarKey)
{

    string connectionString = "Password=password;User Id=user;Data Source=Oracle";

    List<WebinarAttendeesList> r = null;
    using (webinarAttendeesListDbContext context = new webinarAttendeesListDbContext(connectionString))
    {
        var result = from w in context.WebinarAttendeesList
                     where w.webinarKey == webinarKey
                     orderby w.FirstPollCount, w.SecondPollCount
                     select w;
        r = result.ToList();
    }
    return r;
}

Here is the model:

[Table("WEBINARATTENDEESLIST")]
public class WebinarAttendeesList {
    [Key, Column("WAL_ID")]
    public int wa_id { get; set; }
    [Column("WAL_CLI_RID")]
    public int ParticipantID { get; set; }
    [Column("WAL_FULLNAME")]
    public string FullName { get; set; }
    [Column("WAL_EMAIL")]
    public string Email { get; set; }
    [Column("WAL_JOINTIME")]
    public string JoinTime { get; set; }
    [Column("WAL_TIMEINSESSION")]
    public string TimeInSession { get; set; }
    [Column("WAL_LEAVETIME")]
    public string LeaveTime { get; set; }
    [Column("WAL_FIRSTPOLLCOUNT")]
    public int FirstPollCount { get; set; }
    [Column("WAL_SECONDPOLLCOUNT")]
    public int SecondPollCount { get; set; }
    [Column("WAL_ATTENDEDWEBINAR")]
    public int AttendedWebinar { get; set; }
    [Column("WAL_MAKEUP")]
    public int Makeup { get; set; }
    [Column("WAL_COMMENTS")]
    public string Comments { get; set; }
    [Column("WAL_REGISTRANTKEY")]
    public string RegistrantKey { get; set; }
    [Column("WAL_WEBINARKEY")]
    public string webinarKey { get; set; }
}

When the form is submitted, I am passing the model to a function to store the records in EF6.

public ActionResult PostAttendees(ICollection<WebinarAttendeesList> attendees)
{
    foreach (WebinarAttendeesList attendee in attendees)
    {
        UpdateAttendee(attendee);
    }
}

How would I edit the model to allow this delete the records that are selected and update the ones that don't have the checkbox selected? If I put an int delete property on the model that has no Column attribute I get this exception:

ORA-00904: "Extent1"."delete": invalid identifier

I found this tutorial but I'm NOT using any helpers in the creation of the form and do not have any ViewModels and it also doesn't explain how to handle doing different things to the different records based on the checkbox: http://johnatten.com/2014/01/05/asp-net-mvc-display-an-html-table-with-checkboxes-to-select-row-items/

Is there a better way to do this?

4
  • Create a view model with a bool IsSelected property, and when you submit, delete the items where IsSelected == true; Commented Feb 2, 2016 at 23:23
  • I'd rather not create a ViewModel as it will totally make my work harder for this application. That is why I didn't create them in the first place. Commented Feb 2, 2016 at 23:33
  • Are you serious? If you don't want to do this the correct way, you can always add <input type="checkbox" name="attendees" value="@item.wa_id" /> (assuming your using foreach(var item in Model) and then post back to public ActionResult PostAttendees(int[] attendees) and the parameter will contain the ID's of the selected items. Commented Feb 2, 2016 at 23:45
  • The better way to do it is the correct one. You should use a ViewModel for that... You could combine it with a library like Automapper to easily map from the domain model to the view model. Commented Feb 3, 2016 at 1:43

1 Answer 1

1

Yes. All models properties in EF are suppose to be column. You should use NotMapped attribute if you don't want property to be treated as a 'column' in database.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.