列表“实体框架剃刀”

时间:2016-03-25 20:37:50

标签: c# entity-framework razor

<!DOCTYPE html>

<html>



@{
PRO1.Modelo.DBMundo Datos = new PRO1.Modelo.DBMundo();
List<PRO1.Modelo.Country> countrylist = Datos.Country.Distinct().ToList();
List<PRO1.Modelo.City> citylist = Datos.City.Distinct().ToList();
}


<head>
<meta name="viewport" content="width=device-width" />
<title>Paises</title>
</head>
<body>
<p>Seleciona las opciones</p>
<p>Codigo de pais</p>
<form name="formula1" method="post" action="">


    <select name="selcodpais">
        <optgroup label="prueba">
            @{

                foreach (PRO1.Modelo.Country registro in countrylist)
                {
                    <option value="a">@registro.Continent</option>
                }

            }
        </optgroup>

    </select>
    <input type="submit" value="Buscar" />



     </form>



     </body>
     </html>

所以我尝试的是在选择表单上显示表格中的所有项目,但是即使使用.Distinct(),我仍然要保持重复,我只希望每个项目显示一次,也许使用group by但是我还是不知道怎么做,因为我是一个新手,如果你也有一些线索或有关它的信息,我会真的apreciate它 谢谢你的方式

1 个答案:

答案 0 :(得分:1)

需要告诉它是什么让它与众不同 - 否则它会通过对象引用。假设一个国家有一个名字属性......

List<PRO1.Modelo.Country> countrylist = Datos.Country.Distinct(c => c.Name).ToList();