如果同一表匹配的2列上的值

发布于 2025-02-10 14:36:09 字数 1011 浏览 1 评论 0原文

我想获得datacorrespondeid如果mesobjetivo上的值列在currentMonth上是相同的,并且anoobjetivo 列在extryear上是相同的(列在同一表objetivoes)。我想要这个,这样我就可以根据语句根据datacorrespondeid找到语句。是否找到ID。

DateTime now = DateTime.Now;
string currentMonth = DateTime.Now.Month.ToString();
string currentYear = DateTime.Now.Year.ToString();
var datacorrespondeId = bd.Objetivoes.FirstOrDefault(m => m.MesObjetivo == int.Parse(currentMonth) || m.AnoObjetivo == int.Parse(currentYear));

using (Volta12BaseDEntities bd = new Volta12BaseDEntities())
{
    if (datacorrespondeId != null)
    {
        string valorobjetivo = bd.Objetivoes.Where(m => datacorrespondeId.Equals(m.ValorObjetivo)).ToString();
        var Objetivo = new List<Objetivo>()
        {
            new Objetivo{ValorObjetivo = int.Parse(valorobjetivo), MesObjetivo = int.Parse(currentMonth), AnoObjetivo = int.Parse(currentYear)},
        };
    };
};

I want to get the datacorrespondeID if the value on MesObjetivo column is the same on currentMonth, and the value on AnoObjetivo column is the same on currentYear (the columns are on the same table Objetivoes). I want this so I can follow to a If statement according to if datacorrespondeId finds an id or not.

DateTime now = DateTime.Now;
string currentMonth = DateTime.Now.Month.ToString();
string currentYear = DateTime.Now.Year.ToString();
var datacorrespondeId = bd.Objetivoes.FirstOrDefault(m => m.MesObjetivo == int.Parse(currentMonth) || m.AnoObjetivo == int.Parse(currentYear));

using (Volta12BaseDEntities bd = new Volta12BaseDEntities())
{
    if (datacorrespondeId != null)
    {
        string valorobjetivo = bd.Objetivoes.Where(m => datacorrespondeId.Equals(m.ValorObjetivo)).ToString();
        var Objetivo = new List<Objetivo>()
        {
            new Objetivo{ValorObjetivo = int.Parse(valorobjetivo), MesObjetivo = int.Parse(currentMonth), AnoObjetivo = int.Parse(currentYear)},
        };
    };
};

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文