你好,这是我的方法...... [英] Hello, here is my method...

查看:64
本文介绍了你好,这是我的方法......的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

[WebMethod,ScriptMethod(ResponseFormat = ResponseFormat.Json,UseHttpGet = false)]

公共静态动态GetCourses()

{

DB_StudentMarg_DevelopingMainEntities ObjEntities = new DB_StudentMarg_DevelopingMainEntities();

// using(var dbContextTransaction = ObjEntities.Database.BeginTransaction())

// {

尝试

{

tbl_Organization_Registration objRegistration = new tbl_Organization_Registration();

var S =;

S = ObjEntities.tbl_Organization_Registration.Where(u => u.ORG_ID == 1)。选择(u => u.ORG_Course_Type).SingleOrDefault();

var V = S.TrimStart(', ')。TrimEnd(',');

string [] Cources = V.Split(',');

for(int i = 0; i< Cources.Length; i ++)

{

long t = Convert.ToInt64(Cources [i]);

tbl_OrganizationTypeMaster ObjORGTypeMaster = new tbl_OrganizationTypeMaster();

< b> var I =(来自ObjEntities.tbl_OrganizationTypes中的t1

在ObjEntities.tbl_OrganizationTypeMaster中加入t2

on

t1.ORG_ID等于t2.OrganizationTypeID

其中t1.ORG_TypeID == t

选择新的

{

name = t2.OrganizationName

});

}





// dbContextTransaction.Commit();

//返回S;

}

catch(Exception ex )

{

// dbContextTransaction.Rollback();

抛出ex;

}

//}

}





在变量课程中,我有这样的数据( [1,2,3,4,5,6])

我需要将一个列表返回给我的ajax电话......



提前致谢....



我的尝试:



[WebMethod, ScriptMethod(ResponseFormat = ResponseFormat.Json, UseHttpGet = false)]
public static dynamic GetCourses()
{
DB_StudentMarg_DevelopingMainEntities ObjEntities = new DB_StudentMarg_DevelopingMainEntities();
//using (var dbContextTransaction = ObjEntities.Database.BeginTransaction())
//{
try
{
tbl_Organization_Registration objRegistration = new tbl_Organization_Registration();
var S = "";
S = ObjEntities.tbl_Organization_Registration.Where(u => u.ORG_ID == 1).Select(u => u.ORG_Course_Type).SingleOrDefault();
var V = S.TrimStart(',').TrimEnd(',');
string[] Cources = V.Split(',');
for (int i = 0; i < Cources.Length; i++)
{
long t = Convert.ToInt64(Cources[i]);
tbl_OrganizationTypeMaster ObjORGTypeMaster = new tbl_OrganizationTypeMaster();
var I = (from t1 in ObjEntities.tbl_OrganizationTypes
join t2 in ObjEntities.tbl_OrganizationTypeMaster
on
t1.ORG_ID equals t2.OrganizationTypeID
where t1.ORG_TypeID == t
select new
{
name = t2.OrganizationName
});
}


// dbContextTransaction.Commit();
//return S;
}
catch (Exception ex)
{
// dbContextTransaction.Rollback();
throw ex;
}
//}
}


In variable Courses i have the data like this([1,2,3,4,5,6])
I need to return a list to my ajax call...

Thanks in advance....

What I have tried:

IQueryable<tbl_organizationtypemaster> ObjORGTypeMaster=(from t1 in ObjEntities.tbl_OrganizationTypes
                             join t2 in ObjEntities.tbl_OrganizationTypeMaster
                             on
                             t1.ORG_ID equals t2.OrganizationTypeID
                             where t1.ORG_TypeID == t
                             select new
                             {
                                 name = t2.OrganizationName
                             }).tolist();

推荐答案

问题是你在Linq代码中创建了一个匿名类型:

The problem is that you are creating an anonymous type in your Linq code:
select new { name = t2.OrganizationName }

然后使用 ToList 列表<匿名类型> $ c>方法调用。

这与您尝试将其分配给的变量的类型不同: IQueryable< tbl_organizationtypemaster> ObjORGTypeMaster 所以系统抱怨。

尝试创建一个命名类的新实例:

Which you then cast to a List<anonymous type> with the ToList method call.
That isn't the same type as the variable you are trying to assign it to: IQueryable<tbl_organizationtypemaster> ObjORGTypeMaster so teh system complains.
Try creating a new instance of a named class:

select new tbl_organizationtypemaster(){ name = t2.OrganizationName }



下一个问题是 List< T> 没有实现 IQueryable 所以你不能使用 ToList 此处也是。

如果您需要 IQueryable 结果,请使用:


The next problem is that a List<T> does not implement IQueryable so you can't use ToList here either.
If you need an IQueryable result, then use:

... select new tbl_organizationtypemaster(){ name = t2.OrganizationName }).AsQueryable()

而不是。


这篇关于你好,这是我的方法......的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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