Link to home
Create AccountLog in
Avatar of DavidRayRobin
DavidRayRobin

asked on

Linq insert into List

New to Linq, can not figure out why this code isn't working. No error is thrown and clogqry correctly contains 2 items prior to add attempt, but .Add and .Insert doesn't insert a new row, and the item count remains at two.

var clogqry = (from cl in oCustomer.CustomerHotbuttonTypes select cl).ToList();

CustomerHotbuttonType cshbt = new CustomerHotbuttonType();
cshbt.Note = txtHotButtonNote.Text.Trim();
cshbt.CustomerID = oCustomer.ID;
cshbt.HotbuttonTypeID = (int)cboHotButtonType.SelectedValue;

clogqry.Add(cshbt);
//clogqry.Insert(clogqry.Count, cshbt);

Open in new window

ASKER CERTIFIED SOLUTION
Avatar of Wim_Bl
Wim_Bl
Flag of Belgium image

Link to home
membership
Create an account to see this answer
Signing up is free. No credit card required.
Create Account
Avatar of DavidRayRobin
DavidRayRobin

ASKER

Your comments jogged my head, and here is the working code.  Thanks for the quick response.

List<CustomerHotbuttonType> hbt = oCustomer.CustomerHotbuttonTypes;

CustomerHotbuttonType cshbt = new CustomerHotbuttonType();
cshbt.Note = txtHotButtonNote.Text.Trim();
cshbt.CustomerID = oCustomer.ID;
cshbt.HotbuttonTypeID = (int)cboHotButtonType.SelectedValue;

 hbt.Add(cshbt);

Open in new window

Avatar of kaufmed
Is this LINQ-to-SQL or Entity Framework, or is this LINQ-to-Objects?