asp.net mvc 4 - MVC 4 C# How to create a method that returns a list<object> -


i using ef , seeding our db product data. data i'm seeding has part repeated 100 times. rather copy , paste code rather populate list method newbie, cannot seem make work properly:

here code in context:

context.products.addorupdate(             pr => pr.name,             new product             {                 name = "3.5x5",                 productcategoryid = 1,                 productsubcategoryid1 = 1,                 productsubcategoryid2 = 3,                 vendorid = 1,                 heightunitid = 2,                 height = (decimal)3.5,                 width = 5,                 productoptions =                 new list<productoption>                 {                     new productoption { name = "paper", inputtypesingleoptionid = 1, inputtypemultipleoptionid = 2, sortorder = 1,                         productoptionsdetails =                         new list<productoptionsdetail>                         {                             new productoptionsdetail { name = "glossy", value = "glossy", isdefault = true, sortorder = 1 },                             new productoptionsdetail { name = "matte", value = "matte", isdefault = false, sortorder = 2 },                             new productoptionsdetail { name = "metallic", value = "metallic", isdefault = false, sortorder = 3 },                             new productoptionsdetail { name = "lustre", value = "lustre", isdefault = false, sortorder = 4 }                         }                     },                     new productoption { name = "color", inputtypesingleoptionid = 1, inputtypemultipleoptionid = 2, sortorder = 2,                         productoptionsdetails =                         new list<productoptionsdetail>                         {                             new productoptionsdetail { name = "color", value = "color", isdefault = true, sortorder = 1 },                             new productoptionsdetail { name = "black , white", value = "black , white", isdefault = false, sortorder = 2 },                             new productoptionsdetail { name = "sepia", value = "sepia", isdefault = false, sortorder = 3 }                         }                      },                     new productoption { name = "texture", inputtypesingleoptionid = 1, inputtypemultipleoptionid = 2, sortorder = 3,                         productoptionsdetails =                         new list<productoptionsdetail>                         {                             new productoptionsdetail { name = "none", value = "none", isdefault = true, sortorder = 1 },                             new productoptionsdetail { name = "linen texture", value = "linen", isdefault = false, sortorder = 2 },                                                      new productoptionsdetail { name = "canvas texture", value = "canvas", isdefault = false, sortorder = 3 },                             new productoptionsdetail { name = "watercolor texture", value = "canvas", isdefault = false, sortorder = 4 },                             new productoptionsdetail { name = "pebble texture", value = "pebble", isdefault = false, sortorder = 5 }                         }                     },                     new productoption { name = "coating", inputtypesingleoptionid = 1, inputtypemultipleoptionid = 2, sortorder = 4,                         productoptionsdetails =                         new list<productoptionsdetail>                         {                             new productoptionsdetail { name = "none", value = "none", isdefault = true, sortorder = 1 },                             new productoptionsdetail { name = "linen texture", value = "linen", isdefault = false, sortorder = 2 },                                                      new productoptionsdetail { name = "canvas texture", value = "canvas", isdefault = false, sortorder = 3 },                             new productoptionsdetail { name = "watercolor texture", value = "canvas", isdefault = false, sortorder = 4 },                             new productoptionsdetail { name = "pebble texture", value = "pebble", isdefault = false, sortorder = 5 }                         }                     }                 }             }, 

the part return method like: productoptions = getoptions() nested code can repeated verbatim. have tried working other examples keep on getting errors in visual studio. if basic approach this, appreciated.

public list<productoptionsdetail> getoptions() {     return new list<productoptionsdetail>()         {             new productoptionsdetail() { name = "none", value = "none", isdefault = true, sortorder = 1 },             new productoptionsdetail() { name = "linen texture", value = "linen", isdefault = false, sortorder = 2 },                                      new productoptionsdetail() { name = "canvas texture", value = "canvas", isdefault = false, sortorder = 3 },             new productoptionsdetail() { name = "watercolor texture", value = "canvas", isdefault = false, sortorder = 4 },             new productoptionsdetail() { name = "pebble texture", value = "pebble", isdefault = false, sortorder = 5 }         }; } 

Comments

Popular posts from this blog

linux - Does gcc have any options to add version info in ELF binary file? -

android - send complex objects as post php java -

charts - What graph/dashboard product is facebook using in Dashboard: PUE & WUE -