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

Create Function with attribute from database

1 Answer 9 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Milen
Top achievements
Rank 1
Milen asked on 20 Jul 2018, 09:41 AM

     Hallo, 
I have a Data Grid with create, update and destroy functions. I have and database too. My Controller code for create function is: 

public ActionResult Anlage_Create([DataSourceRequest] DataSourceRequest request, MN_ANLAGE anlage)                {                    if (this.ModelState.IsValid)                    {                            using (var anlagen = new TestEntities1())                            {                                    var entity = new MN_ANLAGE                                    {                                     ANLAGEID = anlage.ANLAGEID,                                      ANLAGEART = anlage.ANLAGEART,                                      ANLAGEBETREIBER = anlage.ANLAGEBETREIBER,                                    //  ANLAGEDATA= anlage.ANLAGEDATA,                                      ANLAGENAME=anlage.ANLAGENAME,                                      ANLAGENUMMER=anlage.ANLAGENUMMER,                                      ANLAGESTATUS=anlage.ANLAGESTATUS,                                         TESTBOX = anlage.TESTBOX                                                                     };                                anlagen.MN_ANLAGE.Add(entity);                                anlagen.SaveChanges();                                anlage.ANLAGEID = entity.ANLAGEID;                            }                                    }            return Json(new[] { anlage }.ToDataSourceResult(request, ModelState));                }

 

It is possible to get the properties dynamic from the database in the var entity = new Anlage? Now when i change the database i must to change this method. 
Thank in advance!

 

Kind regards, 

Milen

1 Answer, 1 is accepted

Sort by
0
Konstantin Dikov
Telerik team
answered on 23 Jul 2018, 05:31 AM
Hi Milen,

You already have the instance of the new record in the event arguments (anlage), so you can only assign the ID field to the entity and use the existing one in the Add method. Then, when you make changes to the database structure you could only change the "MN_ANLAGE" class.

Hope this helps.


Regards,
Konstantin Dikov
Progress Telerik
Try our brand new, jQuery-free Angular components built from ground-up which deliver the business app essential building blocks - a grid component, data visualization (charts) and form elements.
Tags
Grid
Asked by
Milen
Top achievements
Rank 1
Answers by
Konstantin Dikov
Telerik team
Share this question
or