How to partition a reactive observable by a key and merge the partitions into groups combine last element of each partition of the group - system.reactive

I have an hot observable of a sequence of items that are have a key that identifies a specific sub-stream. I'm interested to map those M streams into N with N < M (group them into N buckets). For each bucket, each time an element arrives, I want to apply a function to the latest element of each underlining sequence of that group. I've prior knowledge of both N and M groups.
In the following sample, we have a sequence of quote for four fruits. I want to map those streams into two, by the type of fruit (Apple or Pear). For each group I want to collect the last known quote of each fruit.
class Input {
public string ProductID {get;set;}
public string ProductType {get;set;}
public int Price {get;set;}
}
class Output {
public string ProductType {get;set;}
public Input[] Underlining {get;set;}
}
var obs = new List<Input> {
new Input { ProductID = "Stark", ProductType = "Apple", Price = 21 },
new Input { ProductID = "Jonagold", ProductType = "Apple", Price = 12 },
new Input { ProductID = "Williams", ProductType = "Pear", Price = 33 },
new Input { ProductID = "Beth", ProductType = "Pear", Price = 22 },
new Input { ProductID = "Stark", ProductType = "Apple", Price = 43 },
new Input { ProductID = "Williams", ProductType = "Pear", Price = 55 },
new Input { ProductID = "Beth", ProductType = "Pear", Price = 66 },
new Input { ProductID = "Jonagold", ProductType = "Apple", Price = 77 },
new Input { ProductID = "Jonagold", ProductType = "Apple", Price = 25 },
new Input { ProductID = "Williams", ProductType = "Pear", Price = 77 },
new Input { ProductID = "Beth", ProductType = "Pear", Price = 13 },
new Input { ProductID = "Stark", ProductType = "Apple", Price = 21 },
}.ToObservable();
IObservable<Output> result = obs.GroupBy ... Select ... Concat ... ; // I'm a bit loss here
result.Dump();
Expected result:
{ ProductType = "Apple", Underlining = [{ ProductID = "Stark", Price = 21 }] }
{ ProductType = "Apple", Underlining = [{ ProductID = "Stark", Price = 21 }, { ProductID = "Jonagold", Price = 12 }] }
{ ProductType = "Pear", Underlining = [{ ProductID = "Williams", Price = 23 }] }
{ ProductType = "Pear", Underlining = [{ ProductID = "Williams", Price = 23 }, { ProductID = "Beth", Price = 22 }] }
{ ProductType = "Apple", Underlining = [{ ProductID = "Stark", Price = **43** }, { ProductID = "Jonagold", Price = 12 }] }
{ ProductType = "Pear", Underlining = [{ ProductID = "Williams", Price = **55** }, { ProductID = "Beth", Price = 22 }] }
{ ProductType = "Pear", Underlining = [{ ProductID = "Williams", Price = 55 }, { ProductID = "Beth", Price = **66** }] }
{ ProductType = "Apple", Underlining = [{ ProductID = "Stark", Price = 43 }, { ProductID = "Jonagold", Price = **77** }] }
{ ProductType = "Apple", Underlining = [{ ProductID = "Stark", Price = 43 }, { ProductID = "Jonagold", Price = **25** }] }
{ ProductType = "Pear", Underlining = [{ ProductID = "Williams", Price = **77** }, { ProductID = "Beth", Price = 66 }] }
{ ProductType = "Pear", Underlining = [{ ProductID = "Williams", Price = 77 }, { ProductID = "Beth", Price = **13** }] }
{ ProductType = "Apple", Underlining = [{ ProductID = "Stark", Price = **21** }, { ProductID = "Jonagold", Price = 25 }] }

I think this is what you want:
var outputs =
obs
.GroupBy(x => x.ProductType)
.Select(xs =>
xs
.Scan(
new Dictionary<string, Input>(),
(d, x) => { d[x.ProductID] = x; return d; })
.Select(x => new Output()
{
ProductType = xs.Key,
Underlining = x.Values.ToArray(),
}))
.Merge();
I used outputs.Select(x => $"{{ ProductType = \"{x.ProductType}\", Underlining = [{String.Join(", ", x.Underlining.Select(y => $"{{ ProductID = \"{y.ProductID}\", Price = {y.Price} }}"))}] }}") to get the following output to test it:
{ ProductType = "Apple", Underlining = [{ ProductID = "Stark", Price = 21 }] }
{ ProductType = "Apple", Underlining = [{ ProductID = "Stark", Price = 21 }, { ProductID = "Jonagold", Price = 12 }] }
{ ProductType = "Pear", Underlining = [{ ProductID = "Williams", Price = 33 }] }
{ ProductType = "Pear", Underlining = [{ ProductID = "Williams", Price = 33 }, { ProductID = "Beth", Price = 22 }] }
{ ProductType = "Apple", Underlining = [{ ProductID = "Stark", Price = 43 }, { ProductID = "Jonagold", Price = 12 }] }
{ ProductType = "Pear", Underlining = [{ ProductID = "Williams", Price = 55 }, { ProductID = "Beth", Price = 22 }] }
{ ProductType = "Pear", Underlining = [{ ProductID = "Williams", Price = 55 }, { ProductID = "Beth", Price = 66 }] }
{ ProductType = "Apple", Underlining = [{ ProductID = "Stark", Price = 43 }, { ProductID = "Jonagold", Price = 77 }] }
{ ProductType = "Apple", Underlining = [{ ProductID = "Stark", Price = 43 }, { ProductID = "Jonagold", Price = 25 }] }
{ ProductType = "Pear", Underlining = [{ ProductID = "Williams", Price = 77 }, { ProductID = "Beth", Price = 66 }] }
{ ProductType = "Pear", Underlining = [{ ProductID = "Williams", Price = 77 }, { ProductID = "Beth", Price = 13 }] }
{ ProductType = "Apple", Underlining = [{ ProductID = "Stark", Price = 21 }, { ProductID = "Jonagold", Price = 25 }] }

Related

EF Core Fluent API HasData adding delete data on subsequent migration

I am using HasData to seed data and it is creating insert data migration script right but with the subsequent migrations it is adding delete migrations without any further changes.
Entities
Country
public class Country : BaseEntity
{
public string CountryName { get; set; }
}
County
public class County : BaseEntity
{
public string CountyName { get;set; }
public int CountryId { get;set; }
public Country Country { get; set; }
}
BaseEntity
public class BaseEntity
{
public int Id { get; set; }
public Guid ApplicationUserId { get; set; }
}
Configurations
public class CountyConfiguration : BaseEntityConfiguration<County>
{
private const string TABLE_NAME = "Counties";
public CountyConfiguration() : base(TABLE_NAME)
{
}
public override void Configure(EntityTypeBuilder<County> entity)
{
base.Configure(entity);
entity.Property(c => c.CountyName).IsRequired().HasMaxLength(100);
entity.HasIndex(c => c.CountryId).IsUnique(false);
entity.HasIndex(c => new {c.CountyName, c.CountryId }).IsUnique();
entity.HasOne(c => c.Country).WithOne().OnDelete(DeleteBehavior.Cascade);
entity.Ignore(c => c.ApplicationUserId);
entity.HasData(
new County { Id = 1, CountryId = 1, CountyName = "Antrim"},
new County { Id = 2, CountryId = 1, CountyName = "Carlow"},
new County { Id = 3, CountryId = 1, CountyName = "Cavan"},
new County { Id = 4, CountryId = 1, CountyName = "Clare"},
new County { Id = 5, CountryId = 1, CountyName = "Cork"},
new County { Id = 6, CountryId = 1, CountyName = "Derry (Londonderry)"},
new County { Id = 7, CountryId = 1, CountyName = "Donegal"},
new County { Id = 8, CountryId = 1, CountyName = "Dublin"},
new County { Id = 9, CountryId = 1, CountyName = "Galway"},
new County { Id = 10, CountryId = 1, CountyName = "Kerry"},
new County { Id = 11, CountryId = 1, CountyName = "Kildare"},
new County { Id = 12, CountryId = 1, CountyName = "Kilkenny"},
new County { Id = 13, CountryId = 1, CountyName = "Laois (Queens)"},
new County { Id = 14, CountryId = 1, CountyName = "Leitrim"},
new County { Id = 15, CountryId = 1, CountyName = "Limerick"},
new County { Id = 16, CountryId = 1, CountyName = "Longford"},
new County { Id = 17, CountryId = 1, CountyName = "Louth"},
new County { Id = 18, CountryId = 1, CountyName = "Mayo"},
new County { Id = 19, CountryId = 1, CountyName = "Meath"},
new County { Id = 20, CountryId = 1, CountyName = "Monaghan"},
new County { Id = 21, CountryId = 1, CountyName = "Offaly (Kings)"},
new County { Id = 22, CountryId = 1, CountyName = "Roscommon"},
new County { Id = 23, CountryId = 1, CountyName = "Sligo"},
new County { Id = 24, CountryId = 1, CountyName = "Tipperary"},
new County { Id = 25, CountryId = 1, CountyName = "Waterford"},
new County { Id = 26, CountryId = 1, CountyName = "Westmeath"},
new County { Id = 27, CountryId = 1, CountyName = "Wexford"},
new County { Id = 28, CountryId = 1, CountyName = "Wicklow"}
);
}
}
Generated Migration1:
public partial class County : Migration
{
protected override void Up(MigrationBuilder migrationBuilder)
{
migrationBuilder.CreateTable(
name: "Counties",
columns: table => new
{
Id = table.Column<int>(type: "int", nullable: false)
.Annotation("SqlServer:Identity", "1, 1"),
CountyName = table.Column<string>(type: "nvarchar(100)", maxLength: 100, nullable: false),
CountryId = table.Column<int>(type: "int", nullable: false)
},
constraints: table =>
{
table.PrimaryKey("Pk_Counties_Id", x => x.Id);
table.ForeignKey(
name: "FK_Counties_Countries_CountryId",
column: x => x.CountryId,
principalTable: "Countries",
principalColumn: "Id",
onDelete: ReferentialAction.Cascade);
});
migrationBuilder.InsertData(
table: "Counties",
columns: new[] { "Id", "CountryId", "CountyName" },
values: new object[,]
{
{ 3, 1, "Cavan" },
{ 26, 1, "Westmeath" },
{ 25, 1, "Waterford" },
{ 24, 1, "Tipperary" },
{ 23, 1, "Sligo" },
{ 22, 1, "Roscommon" },
{ 21, 1, "Offaly (Kings)" },
{ 20, 1, "Monaghan" },
{ 19, 1, "Meath" },
{ 18, 1, "Mayo" },
{ 17, 1, "Louth" },
{ 16, 1, "Longford" },
{ 27, 1, "Wexford" },
{ 15, 1, "Limerick" },
{ 13, 1, "Laois (Queens)" },
{ 12, 1, "Kilkenny" },
{ 11, 1, "Kildare" },
{ 10, 1, "Kerry" },
{ 9, 1, "Galway" },
{ 8, 1, "Dublin" },
{ 7, 1, "Donegal" },
{ 6, 1, "Derry (Londonderry)" },
{ 5, 1, "Cork" },
{ 4, 1, "Clare" },
{ 2, 1, "Carlow" },
{ 14, 1, "Leitrim" },
{ 28, 1, "Wicklow" }
});
migrationBuilder.CreateIndex(
name: "IX_Counties_CountryId",
table: "Counties",
column: "CountryId");
migrationBuilder.CreateIndex(
name: "IX_Counties_CountyName_CountryId",
table: "Counties",
columns: new[] { "CountyName", "CountryId" },
unique: true);
}
protected override void Down(MigrationBuilder migrationBuilder)
{
migrationBuilder.DropTable(
name: "Counties");
}
}
Next Migration 2: (Without any changes)
public partial class Empty : Migration
{
protected override void Up(MigrationBuilder migrationBuilder)
{
migrationBuilder.DeleteData(
table: "Counties",
keyColumn: "Id",
keyValue: 1);
}
protected override void Down(MigrationBuilder migrationBuilder)
{
migrationBuilder.DeleteData(
table: "Counties",
keyColumn: "Id",
keyValue: 1);
migrationBuilder.InsertData(
table: "Counties",
columns: new[] { "Id", "CountryId", "CountyName" },
values: new object[] { 1, 1, "Antrim" });
}
}
Not sure, why it is adding migrationBuilder.DeleteData delete script?
Here
entity.HasOne(c => c.Country).WithOne().OnDelete(DeleteBehavior.Cascade);
with WithOne() you are basically telling EF that the County.CountryId must be unique (because the only difference between one-to-one and one-to-many in relational databases is the unique constraint (index) for the FK column(s)).
However, before that you are telling EF the opposite
entity.HasIndex(c => c.CountryId).IsUnique(false);
This sequence of conflicting configurations somehow confuses EF and it starts doing strange things.
While this could be considered their bug, at the end the problem is in your code, since apparently you don't want one-to-one relationship. So correct that by replacing HasOne with HasMany
entity.HasOne(c => c.Country).WithMany().OnDelete(DeleteBehavior.Cascade);
or completely remove it since all it does is the same as the default EF Core conventions.
Once you do that, you could also remove the HasIndex configuration since it is also the default by EF Core FK index convention.

sum value and remove duplicates in List

I have this list and want to sum value and remove duplicates in List
1 - check of productName
2 - sum NumberOfItems if productName equals
For Example :
"Orders":[
{
"productName":"Apple",
"NumberOfItems":"5"
},
{
"productName":"Orange",
"NumberOfItems":"2"
},
{
"productName":"Egg",
"NumberOfItems":"5"
},
{
"productName":"Apple",
"NumberOfItems":"3"
},
{
"productName":"Orange",
"NumberOfItems":"4"
},
{
"productName":"Egg",
"NumberOfItems":"9"
},
]
The result I need look like this result : (Sum Depend on productName)
"Orders":[
{
"productName":"Apple",
"NumberOfItems":"8"
},
{
"productName":"Orange",
"NumberOfItems":"6"
},
{
"productName":"Egg",
"NumberOfItems":"14"
},
]
final orders = data["Orders"] as List;
final mapped = orders.fold<Map<String, Map<String, dynamic>>>({}, (p, v) {
final name = v["productName"];
if (p.containsKey(name)) {
p[name]["NumberOfItems"] += int.parse(v["NumberOfItems"]);
} else {
p[name] = {
...v,
"NumberOfItems": int.parse(v["NumberOfItems"])
};
}
return p;
});
final newData = {
...data,
"Orders": mapped.values,
};
print(newData);
Result is:
{Orders: ({productName: Apple, NumberOfItems: 8}, {productName: Orange, NumberOfItems: 6}, {productName: Egg, NumberOfItems: 14})}
Notice: This code has 2 loop which means slower.
Igor Kharakhordin answered smarter one, but may be difficult for those who ask this question.(since he is doing two things at once.) Basically I am doing same thing.
String string = await rootBundle.loadString("asset/data/Orders.json");
Map orders = jsonDecode(string);
List orderList = orders["Orders"];
Map<String,int> sums = {};
for(int i = 0 ; i < orderList.length; i++){
dynamic item = orderList[i];
if(sums.containsKey(item["productName"])){
sums[item["productName"]] += int.parse(item["NumberOfItems"]);
}
else{
sums[item["productName"]] = int.parse(item["NumberOfItems"]);
}
}
List sumList = [];
sums.forEach((key,value)=>
sumList.add({
"productName":key,
"NumberOfItems":value.toString()
})
);
Map result = {
"Orders":sumList
};
print(jsonEncode(result));
Result
{
"Orders": [
{
"productName": "Apple",
"NumberOfItems": "8"
},
{
"productName": "Orange",
"NumberOfItems": "6"
},
{
"productName": "Egg",
"NumberOfItems": "14"
}
]
}

How to group Mongo collection using aggregation while I need other fileds also in result

I facing a situation where I need to query the result from a collection in MongoDB. I want to aggregate my collection based on one field using $group. But I want those remaining fields in my result, but without applying any aggregate functions on these field like ($first, $sum etc). These remaining fields should be in an Array.
Example: My collection:
-------------------------------------------------------------------------
| name | age | sex | province | city| area | address |
-------------------------------------------------------------------------
| A | 22 | m | Manglr | p1 | c1 | a1 |
| A | 22 | m | Kolkt | p2 | c2 | a2 |
| B | 24 | m | Mumb | p3 | c3 | a3 |
| B | 24 | m | Koch | p4 | c4 | a4 |
| B | 24 | m | Hydrbd | p5 | c5 | a5 |
-------------------------------------------------------------------------
Result I want: ($group by 'name' field only)
[
{
"name" : “A”,
"province" : [“Manglr", ‘Kolkt’]
"city" : [“p1”, ‘p2’],
"area" : [“c1”, ‘c2’],
"address" : [“a1”, ‘a2’],
},
{
"name" : “B”,
"province" : [“Mumb", ‘Koch’, 'Hydrbd']
"city" : [“p3”, ‘p4’,”p5”],
"area" : [“c3”, ‘c4’,”c5”],
"address" : [“a3”, ‘a4’,’a5’],
}
]
Please anyone help me to create a Mongo Query or Java code
You can try something like this. Group and push the other fields as needed.
aggregate([{
"$group": {
"_id": "$name",
"province": {
$push: {
"key": "$province"
}
},
"city": {
$push: {
"key": "$city"
}
},
"area": {
$push: {
"key": "$area"
}
},
"address": {
$push: {
"key": "$address"
}
}
}
}, {
"$project": {
"_id": 0,
"name": "$_id",
"province": "$province.key",
"city": "$city.key",
"area": "$area.key",
"address": "$address.key"
}
}])
Sample Output:
{ "province" : [ "Manglr", "kokat" ], "city" : [ "p1", "p2" ], "area" : [ "c1", "c2" ], "address" : [ "a1", "a2" ], "name" : "A" }
{ "province" : [ "Mumb", "Koch" ], "city" : [ "p3", "p4" ], "area" : [ "c3", "c4" ], "address" : [ "a3", "a4" ], "name" : "B" }
I do not know about MongoDB way but following is what you can do Java.
package com.grs.stackOverFlow.pack05;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import java.util.stream.Collectors;
class UserAccumulated{
private String name;
private List<String> city;
private List<Integer> age;
private List<Character> sex;
public UserAccumulated(){
city=new ArrayList<>();
age=new ArrayList<>();
sex=new ArrayList<>();
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public List<String> getCity() {
return city;
}
public void setCity(List<String> city) {
this.city = city;
}
public List<Integer> getAge() {
return age;
}
public void setAge(List<Integer> age) {
this.age = age;
}
public List<Character> getSex() {
return sex;
}
public void setSex(List<Character> sex) {
this.sex = sex;
}
public void addAge(Integer age2) {
age.add(age2);
}
public void addCity(String city2) {
city.add(city2);
}
public void addSex(Character sex2) {
sex.add(sex2);
}
public String toString(){
return String.format("{name:%s,cities : %s, sex: %s, age: %s}", name,city,sex,age);
}
}
public class User {
private String name,city;
private Integer age;
private Character sex;
public User(String name, String city, Integer age, Character sex) {
super();
this.name = name;
this.city = city;
this.age = age;
this.sex = sex;
}
public static void main(String...args){
//create a sample list ..you have to replace with code to retrieve data from mongo db
List<User> rows = Arrays.asList(new User("A", "Manglr", 22, 'm'),
new User("A", "Manglr", 22, 'm'),
new User("B", "addad", 22, 'm'),
new User("C", "addsadad", 22, 'm'),
new User("C", "sadd", 21, 'm'));
//aggregating
List<UserAccumulated> result=new ArrayList<>();
//parallestream if many records else use stream
Map<String, List<User>> map = rows.parallelStream().collect(Collectors.groupingBy(User::getName));
for(Entry<String, List<User>> entry: map.entrySet()){
UserAccumulated userA=new UserAccumulated();
userA.setName(entry.getKey());
for(User user : entry.getValue()){
userA.addAge(user.getAge());
userA.addCity(user.getCity());
userA.addSex(user.getSex());
}
result.add(userA);
}
for(UserAccumulated a: result)
System.out.println(a);
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getCity() {
return city;
}
public void setCity(String city) {
this.city = city;
}
public Integer getAge() {
return age;
}
public void setAge(Integer age) {
this.age = age;
}
public Character getSex() {
return sex;
}
public void setSex(Character sex) {
this.sex = sex;
}
}
Output looks like this:
{ name: A,cities : [Manglr, Manglr], sex: [m, m], age: [22, 22]} {name:B,cities : [addad], sex: [m], age: [22]} {name:C,cities : [addsadad, sadd], sex: [m, m], age: [22, 21]}
I did not take all your columns to keep it simple. I am not sure how quickly it runs with your actual data volume. But if performance issue let me know.

reading Play application configuration file containing nested objects

I want to get list of email IDs based on provided fileType and companyName
def getEmailAddresses(fileType: String, companyName: String): List[String] = {
val xz = Play.application.configuration.getConfigList("email_list")
println(xz)
}
my above function is giving me some complex List of Configuration which is not easily traversable.
I basically want List[String] which is nothing but list of email IDs.
For example, given arguments :
fileType = test_2
companyName = company2
I want to obtain String "user1#gmail.com, user2#gmail.com"
that can be converted to List[String] by .split(",").toList
can this be simplified?
following is my application.conf file in scala play application
email_list = [
{
file0 : "user1#gmail.com,user2#gmail.com"
},
{
file1 : [
{"company1" : "user1#gmail.com"},
{"company2" : "user1#gmail.com"},
{"company3" : "user1#gmail.com"}
]
},
{
top2 = [
{"company1": "user1#gmail.com,user2#gmail.com"},
{"company2": "user1#gmail.com,user2#gmail.com"},
{"company3": "user1#gmail.com,user2#gmail.com"}
]
},
{
test_2 = [
{"company1": "user1#gmail.com,user2#gmail.com"},
{"company2": "user1#gmail.com,user2#gmail.com"},
{"company3": "user1#gmail.com,user2#gmail.com"}
]
},
{
xyz_7 = [
{"company1": "user1#gmail.com,user2#gmail.com"},
{"company2": "user1#gmail.com,user2#gmail.com"},
{"company3": "user1#gmail.com,user2#gmail.com"}
]
},
{
abc_def = [
{"company1": "user1#gmail.com,user2#gmail.com"},
{"company2": "user1#gmail.com,user2#gmail.com"},
{"company3": "user1#gmail.com,user2#gmail.com"}
]
}
]
I have done some trials on HOCON Syntax and found following code + config to be working
code
def getEmailAddresses(fileType: String, companyName: String): List[String] = {
// fileType = "file1"
// companyName = "company1"
val file0 = Play.application.configuration.getString("email_list.file0")
println(file0)
val file1_company1 = Play.application.configuration.getString(s"email_list.${fileType}.${companyName}")
println(file1_company1)
}
application conf
email_list {
file0 = "user1#gmail.com,user2#gmail.com"
file1 {
company1 = "user1#gmail.com"
company2 = "user1#gmail.com"
company3 = "user1#gmail.com"
}
top2 {
company1 = "user1#gmail.com,user2#gmail.com"
company2 = "user1#gmail.com,user2#gmail.com"
company3 = "user1#gmail.com,user2#gmail.com"
}
test_2 {
company1 = "user1#gmail.com,user2#gmail.com"
company2 = "user1#gmail.com,user2#gmail.com"
company3 = "user1#gmail.com,user2#gmail.com"
}
xyz_7 {
company1 = "user1#gmail.com,user2#gmail.com"
company2 = "user1#gmail.com,user2#gmail.com"
company3 = "user1#gmail.com,user2#gmail.com"
}
abc_def {
company1 = "user1#gmail.com,user2#gmail.com"
company2 = "user1#gmail.com,user2#gmail.com"
company3 = "user1#gmail.com,user2#gmail.com"
}
}

ASP.NET MVC 2: Manually create a list and attach to model

I have a model:
[Required]
public List<SelectList> Meals { get; set;
}
And I want to create a list in my Controller so I can attach it to "Meals" in my Model.
For some reason I'm having issues doing this:
_model.MaxCoupons = new List<SelectListItem>();
SelectListItem _mList = new SelectListItem([]{
new SelectListItem { Text = "---", Value = "" },
new SelectListItem { Text = "50", Value = "50" },
new SelectListItem { Text = "60", Value = "60" },
new SelectListItem { Text = "70", Value = "70" },
new SelectListItem { Text = "80", Value = "80" },
new SelectListItem { Text = "90", Value = "90" },
new SelectListItem { Text = "100", Value = "100" },
new SelectListItem { Text = "110", Value = "110" },
new SelectListItem { Text = "120", Value = "120" },
new SelectListItem { Text = "130", Value = "130" },
new SelectListItem { Text = "140", Value = "140" },
new SelectListItem { Text = "150", Value = "130" } },
"Text", "Value" );
_model.MaxCoupons.Add(_mList);
I'm a bit confused right now...
public SelectList Meals { get; set; }
public SelectList MySelectList()
{
List<SelectListItem> _returnList = new List<SelectListItem>();
SelectListItem _mList = new SelectListItem();
_mList = new SelectListItem(){ Text = "---", Value = "" };
_returnList.Add(_mList);
//keep repeating
}
then inside a method:
Meals = new MySelectList();