Linq returning multiple values in a group by, need only last modified -



Linq returning multiple values in a group by, need only last modified -

i have next linq, want lastly product modified in day, illustration @ begginning of day have 2000 products (cajasdia), @ noon have 500 products (cajasdia), linq giving me total list of modifications of products in day, want lastly record of modified product (only 500)

this involves 3 tables, producto (products), productosubregion , subregion, there lot of products containing in part , part contains lot of products.

this relation between tables: producto 1..* productosubregion *..1 subregion

list<productoagr> _productos = (from p in db.productosubregion.include("producto") orderby p.fecha descending p.subregion.idsubregion.equals( (from c in db.cliente bring together v in db.vendedor on c.idvendedor equals v.idvendedor c.idcliente.equals(_idcliente) select c.vendedor.subregion.idsubregion).firstordefault()) && (p.fecha >= today && p.fecha < tomorrow) grouping p new { p.producto.idproducto, p.producto.nombre, p.producto.precio, p.producto.descripcion, nombreproducto = p.producto.tipoproducto.nombre, p.fecha, p.cajasdia } ps select new productoagr() { idproducto = ps.key.idproducto, nombre = ps.key.nombre, precio = ps.key.precio, descripcion = ps.key.descripcion, nombreproducto = ps.key.nombreproducto, cajasdia = ps.key.cajasdia, fecha = ps.key.fecha }).tolist(); homecoming view(_productos);

this i'm getting, should getting 1 record, 1496 value product1

i split linq 2 linqs, working, have one, since improve performance...

for having similar problem, short explanation, first linq gets products of day belongs region order fecha (which date value); sec linq grouping values unique values, such id of product, name, cost , description.

hope helps else.

list<productosubregion> _subregion = (from p in db.productosubregion.include("producto") p.subregion.idsubregion.equals( (from c in db.cliente bring together v in db.vendedor on c.idvendedor equals v.idvendedor c.idcliente.equals(_idcliente) select c.vendedor.subregion.idsubregion).firstordefault()) && (p.fecha >= today && p.fecha < tomorrow) select p).orderbydescending(y => y.fecha).tolist(); list<productoagregar> _productos = (from t in _subregion grouping t new { t.producto.idproducto, t.producto.nombre, t.producto.precio, t.producto.descripcion, nombreproducto = t.producto.tipoproducto.nombre } ps select new productoagregar() { idproducto = ps.key.idproducto, nombre = ps.key.nombre, precio = ps.key.precio, descripcion = ps.key.descripcion, nombreproducto = ps.key.nombreproducto, cajasdia = ps.select(u => u.cajasdia).firstordefault(), fecha = ps.select(u => u.fecha).firstordefault(), }).tolist(); homecoming view(_productos);

the main difference place utilize orderby, couldn't find answer...

linq linq-to-entities

Comments

Popular posts from this blog

delphi - blogger via idHTTP : error 400 bad request -

c++ - cuda, pycuda -- how to write complex numbers -- errors:class "cuComplex" has no member "i" -

How do I check if an insert was successful with MySQLdb in Python? -