This is a migrated thread and some comments may be shown as answers.

How to remove duplicates entries in database using Telerik MVC Grid and LINQ?

1 Answer 242 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Ajdin
Top achievements
Rank 1
Ajdin asked on 28 Jan 2015, 04:43 AM
   public ActionResult Drzave_Create([DataSourceRequest]DataSourceRequest request, [Bind(Prefix = "models")]IEnumerable<DrzaveViewModel> drzave)
        {
            
                // Will keep the inserted entitites here. Used to return the result later.
                var entities = new List<Drzave>();
                if(ModelState.IsValid)
                {
                    using(var autoOtpad = new AutoOtpadEntities())
                    {
                        var product = new List<Drzave>();
                            foreach(var drzava in drzave)
                            {

                                // Create a new Product entity and set its properties from the posted ProductViewModel
                                var entity = new Drzave
                                {
                                    DrzavaId = drzava.DrzavaId,
                                    Naziv = drzava.Naziv,
                                    PuniNaziv = drzava.PuniNaziv  

                                };


                            }
                              // THIS IS NOT WORKING FOR ME...
                             var query = autoOtpad.Drzave.Where(x => x.Equals(product).ToList();

                             if (query != null)
                             {
                                  // row exists

                             }
                             else 
                             {
                                 // update DB// Add the entity
                                autoOtpad.Drzave.Add(entity);
                                // Store the entity for later use
                                entities.Add(entity);
                             }
                        // Insert the entities in the database
                         autoOtpad.SaveChanges();
                    }
                }
        
                // Return the inserted entities. The grid needs the generated ProductID. Also return any validation errors.
                return Json(entities.ToDataSourceResult(request, ModelState, drzava => new DrzaveViewModel
                {
                    DrzavaId = drzava.DrzavaId,
                    Naziv = drzava.Naziv,
                    PuniNaziv = drzava.PuniNaziv
                }));
        }  
    }




1 Answer, 1 is accepted

Sort by
0
Petur Subev
Telerik team
answered on 30 Jan 2015, 07:14 AM
Hello Ajdin,

Getting the distinct objects from a database is not a question related to Kendo. You can search the internet for similar questions.

http://stackoverflow.com/questions/4539668/entity-framework-select-distinct-name

Kind Regards,
Petur Subev
Telerik
 

Check out the Telerik Platform - the only platform that combines a rich set of UI tools with powerful cloud services to develop web, hybrid and native mobile apps.

 
Tags
Grid
Asked by
Ajdin
Top achievements
Rank 1
Answers by
Petur Subev
Telerik team
Share this question
or