使用LINQ查询 [英] Query using LINQ issue

查看:58
本文介绍了使用LINQ查询的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

你好,

我有一个小问题,希望您能帮助我解决.
因此,我必须在gridview中显示有关患者及其下次约会时间表的一些信息.
唯一的问题是我不确定(相信我,在这里提交问题之前我已经尝试了很多事情)如何执行此操作:
我要从所有用户中选择一些信息(地址,联系方式,生日等),然后如果该用户是男性计划约会3个月,如果该用户是女性计划约会4个月.
我怎样才能做到这一点?拜托,我真的很感激!
查询(主要查询-没有这种比较,我真的不知道该如何处理):

Hi there,

I have a small issue, which I hope you can help me solve it.
So, I have to display in gridview some information about patients and theirs schedules for next appointments.
The only problem is that I`m not sure (trust me, I`ve tried a lot of things before I submitted my question here) how to do this:
From all users, I want to select some infos (address, contact, birthdate, etc) and then if the user is male schedule appointment for 3 months and if is a female schedule it for 4 months.
How can I do that? Please, I would really appreciate it!
The query (the main one- without this comparison which I really dont know how to handle):

public static object getUsersAppointments()
{
var qUsersApp=(from u in dc.UsersApp
select new
{
   u.lname,
   u.bday,
   u.address,
   u.lastapp,
   NextApp = lastapp.Value.AddMonths(and this is part I dont know how to handle)
}).ToList();
return qUsersApp;
}




文本是从OP的以下非解决方案"中移出的:
当然,它具有性属性.我的疑问是如何在此查询中按性别过滤?可能是非常愚蠢的问题,但是这些天我筋疲力尽,觉得不太好.感谢您的重放和建议.




Text moved from OP''s "not solution" below:
Of course it have sex property. My doubt is how to inside this query filter by sex?! Probably very stupid question, but I`m exhausted and dont think very good these days. Thank you for replays and suggestions.

推荐答案

public static object getUsersAppointments()
{
  var qUsersApp=(from u in dc.UsersApp
  select new
   {
    u.lname,
    u.bday,
    u.address,
    u.lastapp,
    NextApp=get_Schedule(dc.Gender,u.lastapp)
   }).ToList();
  return qUsersApp;
}

 private DateTime get_Schedule(string Gender,DateTime date)
 {
   DateTime dt;
    if(Convert.ToString(Gender)=="male")
     {
       dt=date.AddMonths(3);
     }
    else
     {
       dt=date.AddMonths(4);
     }
  return dt;
}


我有您的问题. 希望您的数据库表是这样..

表名称=> "PersonData"

姓名地址电话LastApp性别
男| 23号街| 344/333 | 10/7/12 | M
女| 23号街| 344/333 | 10/7/12 | F

Hi i got your prob..
Hope your database tabel is like this..

Table Name => "PersonData"

Name Address Tel LastApp Gender
Male | Street no 23 | 344/333 | 10/7/12 | M
Female | Street no 23 | 344/333 | 10/7/12 | F

var PersonDtls=from Person in PersonData.AsEnumerable()
               select{
                        Name=Person.Field<string>("Name"),
                        Address=Person.Field<string>("Address"),
                        Phone=Person.Field<string>("Tel"),
                        LastApp=Person.Field<datetime>("LastApp"),
                        NextApp=Person.Field<string>("Gender")=="M"?Person.Field<datetime>("LastApp").AddMonths(3):Person.Field<datetime>("LastApp").AddMonths(4)
                     };



希望这会对您有所帮助.
所有的赌注..



Hope this will help you..
All the bets..


这篇关于使用LINQ查询的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆