日期:2014-05-17 浏览次数:21059 次
/// <summary>
/// 全局返回类型
/// </summary>
/// <typeparam name="T"></typeparam>
public class Result<T>
{
public bool Success { get; set; }
public T Data { get; set; }
}
/// <summary>
/// 根据用户IP获取实体
/// </summary>
/// <param name="ip"></param>
/// <returns></returns>
[WebMethod]
public Result<User> GetUserByIp(string ip)
{
var result = new Result<User>();
using (var ctx = new ZpDscContext())
{
var UserObj = ctx.Users.FirstOrDefault(u => u.LoginIp == ip);
result.Success = true;
result.Data = UserObj;
}
return result;
}
/// <summary>
/// 根据用户IP获取实体
/// </summary>
/// <param name="ip"></param>
/// <returns></returns>
public Result<User> GetUserByIp(string ip)
{
var result = new Result<User>();
using (var ctx = new ZpDscContext())
{
var UserObj = ctx.Users.FirstOrDefault(u => u.LoginIp == ip);
result.Success = true;
result.Data = UserObj;
}
return result;
}
//这样写就不报错 但是不是我想要的
[WebMethod]
public int test(string ip)
{
return GetUserByIp(ip).Data.UserId;
}
[Serializable()] //加上这个
public class Result<T>
{
public bool Success
{
get; set;
}
public T Data
{ get; set;
}
}