简体   繁体   English

在“实体框架剃刀”列表上的不同查询项

[英]Distinct items of query on a list “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>

So what im trying is to display all the items form the table on the select form, but i keep geting theese duplicates even using .Distinct(), i only want to be displayed one time per item, maybe using group by but i still dont know how to do it since im a newbie if u also have some clue or information about it i will really apreciate it Thanks by the way 所以我正在尝试在选择表单上显示表格中的所有项目,但是即使使用.Distinct()我也一直在获取这些副本,我只希望每个项目显示一次,也许使用分组依据,但我仍然不自从我是一个新手以来,我就知道该怎么做,如果您也有一些线索或信息,我会很感激的

Need to tell it what makes it distinct -- otherwise it goes by object reference. 需要告诉它是什么使它与众不同-否则它通过对象引用进行。 Assuming a country has a Name property... 假设一个国家拥有Name属性...

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM