我有一个充满坐标(x,y)的数据库,我希望找到最接近点的坐标.(可能有多个最接近这一点)
我已经写了这2个LINQ,但必须有一个聪明的方法,而不是通过数据库两次:
var closestDistance = _context.Coordinates.Min(x =>
Math.Sqrt(Math.Pow((point.coordX - x.CoordX), 2) +
Math.Pow((point.coordY- x.CoordY), 2)));
var closest = _context.Coordinates.Where(x=> closestDistance ==
Math.Sqrt(Math.Pow((point.coordX - x.CoordX), 2) +
Math.Pow((point.coordY - x.CoordY), 2)));
Run Code Online (Sandbox Code Playgroud)
我该如何优化呢?
我有一些问题.我有2个班:Carorder:
<?php
namespace AppBundle\Entity;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\ORM\Mapping as ORM;
use AppBundle\Entity\Orderdetail;
/**
* @ORM\Entity
* @ORM\Table(name="carorder")
*/
class Carorder
{
/**
* @ORM\Column(type="integer")
* @ORM\Id
* @ORM\GeneratedValue
*/
protected $id;
/**
* @ORM\OneToMany(targetEntity="Orderdetail", mappedBy="Carorder", cascade={"persist","remove"})
**/
protected $orderdetails;
//Then all the auto genereted setters and getters beneath here
Run Code Online (Sandbox Code Playgroud)
订单详情:
<?php
namespace AppBundle\Entity;
use Doctrine\ORM\Mapping as ORM;
use Doctrine\Common\Collections\ArrayCollection;
/** @ORM\Entity
* @ORM\Table(name="orderdetail")
*/
class Orderdetail
{
/**
* @ORM\Column(type="integer")
* @ORM\Id
* @ORM\GeneratedValue
*/
protected $id;
/**
* @ORM\ManyToOne(targetEntity="Carorder", …Run Code Online (Sandbox Code Playgroud)