Ok, got my query going, up and running but it doesn't appear that I have got it working correctly!!
My query is as follows:
MyEnt updatefeedback = new MyEnt();
tblWeight newfeedback = (
from weight in updatefeedback.tblWeights
where weight.MemberId == memberid
where weight.LocationId == locationid
where weight.PriKey == prikeyint
select weight).Single();
newfeedback.Feedback = feedbacktext;
updatefeedback.SaveChanges();
Basically, all I am trying to do is insert the no feedback text (feedbacktext) into Feedback. However, despite everything looking good and being populated, I don't believe tblWeight is actually being updated.
Any advice, greatly appreciated.
Thanks for the profiler tip Morteza.
It was indeed working absolutely fine - I was being an idiot and re populating the radgrid's item template each time it loads...silly me.
Related
Obvious attempt here is to get phone calls by a specific account ID, and ONLY phonecalls which have a regardingobject type of "account" (this is only a basic part of the full call, but even this fails).
var linqPhonecalls = from pc in svcContext.PhoneCallSet
where ((pc.RegardingObjectId.Id == account.Id) && (pc.RegardingObjectId.LogicalName == "account"))
select new
{
subj = pc.Subject,
stateCD = pc.StateCode,
};
Through research on the net I ran into this idea ( http://informeddynamicscrm.blogspot.com/2012/01/linq-restrictions-with-crm-2011-xrm.html ) and tried the following:
pc.RegardingObjectId.LogicalName.Equals("account") == true
As well as using Contains() and any other comparison operations I could try. It seems like the major problem here is the use of .LogicalName (also tried .Name)
Because I can't get it to work, I'm going to leave that check out of the equation for now, but I'd really like to put it in there because I'm going to be joining against other regarding types and want to sort things out.
I cannot understand what is wrong with following query:
var tmp = dbset.AsEnumerable<mytable>().Where(
c=>c.Barcode.Contains("11") && c.Description.Contains("EW") );
return tmp;
Should this be same as:
select * from mytable
where Barcode like '%11%' and Description like '%EW%';
If I run this in sql server i get four rows as it should be, but not when I run the linq query
i get 0 rows.
Can please someone help me. It is rather a simple query and it is giving me such a headache. Thank you very much
You forget fetch data, do this:
var tmp = dbset.AsEnumerable<mytable>().Where(
c=>c.Barcode.Contains("11") && c.Description.Contains("EW") );
return tmp.ToList();
Also do not call AsEnumerable soon, use it as below:
var tmp = ctx.mytable.Where(
c=>c.Barcode.Contains("11") && c.Description.Contains("EW") );
return tmp.ToList();
dbset.AsEnumerable<mytable>()...
Don't do that!
You are causing all your data to get pulled from the database before checking the Where condition.
Other than that, it's not really clear why your query isn't working. Your syntax is correct. I'm guessing the data doesn't actually look like you think it does. Either that, or you're expecting like %EW% to match something in a case-insensitive manner and since the Where clause is being evaluated by LINQ to Objects you're not getting that behavior.
Run a query with only one condition? " c.Barcode.Contains("11") ".
That code should run fine.
everyone! ))
Here is code.
var existingEntities = (from record in globalOne.serviceContext.records_out
where record.timestamp.Date == DateTime.Now.Date
select record ).ToList();
It doesn't work.
Another code:
var existingEntities = (from record in globalOne.serviceContext.records_out
where record.timestamp.Day == DateTime.Now.Day
select record ).ToList();
It does work.
So, problem id in next string:
where record.timestamp.**Date** == DateTime.Now.Date
also won't do
where record.timestamp.Date.Equals(DateTime.Now.Date)
But why? I have no clue. "Timestamp" field is dateTime field in MS SQL SERVER.
And - there is NO records in table.
And I almost forgot - what does it mean - "doesn't work".
App just will not reach the breakpoint after that query(first), without any error, without anything.
Thanks.
You can call record.timestamp.Date because EF can't convert it to required expression tree (then convert it to sql command). In fact EF supports limited number of functions and properties, But for DateTime, EF has some good Canonical functions. You can use them in your case, e.g you can use Day(),Month(),Year() functions to solve your problem (see the link).
I beg your solution to my script in PowerBuilder. I think it's fine but doesn't work properly.
Here's the script:
long ll_newrow
ll_newrow = dw_2.InsertRow(0)
dw_2.object.rectype[ll_newrow] = 'I'
dw_2.object.procyear[ll_newrow] = off_procyear
dw_2.object.procmth[ll_newrow] = off_procmth
dw_2.object.batchno[ll_newrow] = off_batchno
dw_2.object.pibseqno[ll_newrow] = pib_max
//dw_2.object.modifydate[ll_newrow] = id_modifydate
//dw_2.object.modifier[ll_newrow] = 'I-' + TRIM(is_modifier)
dw_2.ScrollToRow(ll_newrow)
dw_2.setcolumn("pibseqno")
dw_2.SetFocus()
Data in dropdown list that I've made in DataWindow doesn't show in run time, but it's fine in development.
You'll probably want to do a GetChild on the column in question, SetTransObject() on the DataWindowChild, then Retrieve() on the DataWindowChild. There are many ways to populate a DropDownDataWindow (I'm assuming it's a DDDW that you're asking about), but this is the most common, other than maybe AutoRetrieve which AFAIK isn't applicable when you only do an InsertRow().
Good luck,
Terry.
Any way to make this more efficient?
internal Func<enntities, IQueryable<CategoryList>> GetCategoryListWithPostingCount =
CompiledQuery.Compile((entities entities) =>
from c in entities.Categories.Include("Postings_Categories")
where c.ParentCategoryID == null
orderby c.DisplayOrder
select new CategoryList
{
ParentCategoryName = c.CategoryName,
ParentCategoryID = c.CategoryID,
SubCategories = (
from s in entities.Categories
where s.ParentCategoryID == c.CategoryID
select new SubCategoryList
{
PostingCount = s.Postings_Categories.Count,
SubCategoryName = s.CategoryName,
SubCategoryID = s.CategoryID
})
});
Any suggestions for improvement would depend on us knowing a lot more than just the LINQ query. For example, if you have a lot of SubCategoryLists per Category, and if Category has a lot of scalar data attached to it (big description text, etc), it might be faster to pull the category list in a separate database round-trip. But it probably won't.
Looking at what tables are joined and adding the appropriate indices could make a difference, too.
But all in all, I'd say this is a case of premature optimization. The code looks clean, and I can tell what you're trying to do with it, so call that good for now. If you find that it's a slow point in your program, worry about it then.
PS--The question is tagged LINQ-to-SQL, but this looks like LINQ-to-Entities to me...