Hi i am using following code to fetch userID present in Gateway_users table to Appterms table. But problem is whenever i run solution I am getting duplicate records, that is first time 100 records with ID's and second time 200 records with duplicate ID's so on.
public class HomeController : Controller
{
private AppMarketplaceEntities db = new AppMarketplaceEntities();
private InstallTrackerEntities db1 = new InstallTrackerEntities();
public ActionResult Index()
{
List<int> gatewayUserId = new List<int>();
using (var ctx = new InstallTrackerEntities())
{
gatewayUserId = ctx.Gateway_Users.Select(f => f.GatewayuserUID).ToList();
}
using (var ctx2 = new AppMarketplaceEntities())
{
foreach (var id in gatewayUserId)
{
ctx2.AppTerms.Add
(new AppTerm(){ GatewayuserUID = id });
}
ctx2.SaveChanges();
}
return View();
} } }
So what changes I have to make to above code to get only ID's which are present in Gateway_users table and it should fetch only once and not duplicate records.