Please help with my task.
I need to extract data from database and pack it in collection of object.
I try this code
DataClasses1DataCotext db = new DataClesses1DataContext();
IEnumerable<SimpleSMS> newSmses = db.SimpleSMS.GetEnumerator();
.....
but I haven't idea how to add filter (where db.SimpleSMS.Status = null)
Try the LINQ query:
IEnumerable<SimpleSMS> newSmses = (from pld in db.SimpleSMS
where pld.Status == null
select pld).GetEnumerator();
I hope it will help you.. :)
IEnumerable<SimpleSMS> newSmses = db.SimpleSMS.Where(s => s.Status == null).AsEnumerable();
Related
$query = $em->query("
SELECT c.id AS id
FROM collectif c, zone z
WHERE
c.zone_id = z.id
AND z.label = '$zone'
ANDc.collectif = '$collectif'
");
$c = $query->fetchAll();
$idc = $c['id'];
I have this query that returns a single line, Symfony shows me an error as what variable id undefined
NB: I know that's don't respect the concept of Symfony [MVC] but it's for a particular reason so if someone can tell me how I can resolve this problem
Thank you
$query->fetchAll() should return numeric array of elements so key id does not exists. You should try $c[0]['id'] to get value.
If you'd rather use the results in the assocative way, you can use fetchAssoc() instead:
$c = $query->fetchAssoc();
$idc = $c['id'];
Here is the documentation for reference:
http://docs.doctrine-project.org/projects/doctrine-dbal/en/latest/reference/data-retrieval-and-manipulation.html#fetchassoc
I'm just giving an alternate way to do this.
I'm having a challenge with the following string:
Datedeath: IIf([Members.Status]=[“DA”] Or [“DB”] Or [“DJ”] Or [“DC”], else [members.deathdate] "29/02/1844"
Might someone be able to guide me as to how to write this iif statement please?
Check if the condition fulfilled, set new date or leave it
[members.deathdate]:IIf ((([Members.Status] = "DA" Or [Members.Status] = "DB" Or [Members.Status] = "DJ" Or [Members.Status] = "DC") And ([members.deathdate] = "" Or IsNull([members.deathdate]))), "29/02/1844", [members.deathdate])
I Use KendoUI Grid and I have a code like this :
IQueryable<ListStatus> liststatus = (from karfarmalist in db.PTStbLists
join eventlist in db.PTStbListEvents on karfarmalist.Id equals eventlist.SerialList
join combobase in db.GlbTbComboBases on eventlist.EventType equals combobase.GUID
where karfarmalist.TFN.Equals(tfn) && karfarmalist.GuidList == listid
select new ListStatus{
id = eventlist.Id,
eventdate = Farab.Utility.PersianDate.Georgian_jalali(eventlist.EventDate),
status = combobase.FAName
}).OrderBy(l => l.id);
Farab Call Raise an error. I use AsEnumerable method but orderby has error. How can I call that method in LINQ without error?
You can add .ToList() at the end of the query but that would cause a call to be made to the db, which will affect performance of the query. Not sure if this is what you want but you can give it a try.
I'm trying to match md5(ID) to an id.
SELECT *
FROM `user` u
WHERE
MD5(`user_id`) = '66f041e16a60928b05a7e228a89c3799'
this is ID = 58
I tried something like this. I know I'm close I just don't know what I'm missing
$criteria = new Criteria();
$criteria->addAnd('md5('.User::USER_ID.')', $_REQUEST['fs'], Criteria::CUSTOM);
$user = UserPeer::doSelectOne($criteria);
Any ideas?
First of all, directly using Criteria objects is deprecated not recommended. You should use Active Query classes.
Using these classes, you will be able to write stuff like this :
UserQuery::create()
->where('md5(User.Password) = ?', $_REQUEST['fs'], PDO::PARAM_STR)
->findOne();
You'll notice that I use the PhpName both of the table and the column in the query.
EDIT : For raw conditions, the parameter type has to be specified. You'll find more information on this issue.
After lenghty T&E process I managed to get it done like this
$c = new Criteria();
$c->add(UserPeer::USER_ID, "md5(user.user_id) = \"".$_REQUEST['fs']."\"", Criteria::CUSTOM); // risk of SQL injection!!
$saved_search = UserPeer::doSelectOne($c);
For some reason PropelORM though that $_REQUEST['fs'] was name of the table rather than the value. \"" solved the problem.
I'm a newbie with the IQueryable, lambda expressions, and LINQ in general. I would like to put a subquery in a where clause like this :
Sample code :
SELECT * FROM CLIENT c WHERE c.ETAT IN (
SELECT DDV_COLUMN_VAL FROM DATA_DICT_VAL
WHERE TBI_TABLE_NAME = 'CLIENT' AND DD_COLUMN_NAME = 'STATUS'
AND DDV_COLUMN_VAL_LANG_DSC_1 LIKE ('ac%'))
How do I translate this in LINQ ?
var innerquery = from x in context.DataDictVal
where x.TbiTableName == myTableNameVariable
&& x.DdColumnName == "Status"
&& x.DdbColumnValLangDsc1.StartsWith("ac")
select x.DdvColumnVal;
var query = from c in context.Client
where innerquery.Contains(c.Etat)
select c;
from c in db.Client
where (from d in db.DataDictVal
where d.TblTableName == "Client"
&& d.DDColumnName == "Status"
&& dd.DdvColumnValLandDsc1.StartsWith("ac"))
.Contains(c.Etat)
select c;
If you are new to Linq, you absolutely need two essential tools. The first is a tool that converts most T-SQL statements to Linq called Linqer (http://www.sqltolinq.com/). This should take care of the query in your question. The other tool is LinqPad (http://www.linqpad.net/). This will help you learn Linq as you practice with queries.
I often use Linqer to convert a T-SQL query for me, and then use LinqPad to fine tune it.
Same example with Linq method syntax:
var innerquery = dbcontext.DataDictVal
.where(x=> x.TbiTableName == myTableNameVariable
&& x.DdColumnName == "Status"
&& x.DdbColumnValLangDsc1.StartsWith("ac"))
.select(x=>x.DdvColumnVal)
var query = dbcontext.Client
.where( c=>innerquery.Contains(c.Etat))
Note:
Am providing this answer, because when i searched for the answer, i couldn’t find much answer which explains same concept in the method syntax.
So In future, It may be useful for the people, those who intestinally searched method syntax like me today.
Thanks
karthik