PDA

View Full Version : Type Casting



Aidin
چهارشنبه 08 آبان 1387, 16:57 عصر
سلام

من یه SP دارم و خروجی اون را می خوام به یه Type تبدیل کنم

با یه تابع تو DAL این کارو انجام میدم :


public IQueryable<TypeTimeEvent> GetTime4Chart(string IP, string PC, string User)
{
SINADataClassesDataContext MyDB = new SINADataClassesDataContext();

var Q = (
from p in MyDB.Chart_Get24Hour(IP, PC, User)
select new TypeTimeEvent() { ID = Convert.ToInt32(p.ID), SumDur = Convert.ToInt32(p.SumDur), SumDurS = p.SumDurS, Hour = p.Hour });


return Q;
}ولی این Error رو میگیره :

Error 5 Cannot implicitly convert type 'System.Collections.Generic.IEnumerable<SINA_Web_Interface.TypeTimeEvent>' to 'System.Linq.IQueryable<SINA_Web_Interface.TypeTimeEvent>'. An explicit conversion exists (are you missing a cast?)

mohammad272005
پنج شنبه 09 آبان 1387, 02:27 صبح
سلام

من یه SP دارم و خروجی اون را می خوام به یه Type تبدیل کنم

با یه تابع تو DAL این کارو انجام میدم :


public IQueryable<TypeTimeEvent> GetTime4Chart(string IP, string PC, string User)
{
SINADataClassesDataContext MyDB = new SINADataClassesDataContext();

var Q = (
from p in MyDB.Chart_Get24Hour(IP, PC, User)
select new TypeTimeEvent() { ID = Convert.ToInt32(p.ID), SumDur = Convert.ToInt32(p.SumDur), SumDurS = p.SumDurS, Hour = p.Hour });


return Q;
}ولی این Error رو میگیره :

Error 5 Cannot implicitly convert type 'System.Collections.Generic.IEnumerable<SINA_Web_Interface.TypeTimeEvent>' to 'System.Linq.IQueryable<SINA_Web_Interface.TypeTimeEvent>'. An explicit conversion exists (are you missing a cast?)

خیلی ساده این کارو بکن:


public System.Linq.IQueryable<SINA_Web_Interface.TypeTimeEvent> GetTime4Chart(string IP, string PC, string...

Aidin
پنج شنبه 09 آبان 1387, 04:00 صبح
کجا این کد رو باید بنویسم ؟؟
توی DAL یا توی BLL ؟؟

mohammad272005
پنج شنبه 16 آبان 1387, 00:43 صبح
چون به یه Entity مستقیم ختم نمی شه، به نظر من باید تو DAL همون جا که تابع هست نوشته بشه.