I want to two column value in entity but I
dont selected.
How to solve select problem.
Try code:
var t1= dbcontext.Entities.Student.Select(c=>c.Number , a=>a.branchcode).
I error branchcode area.
But ı select number and branchcode.
You can try this code:
var t1 = dbcontext.Entities.Student.Select(c => new { Number = c.Number, Branchcode = c.Branchcode });
Related
I am having trouble with en EF method returning duplicate rows of data. When I am running this, in my example, it returns four rows from a database view. The fourth row includes details from the third row.
The same query in SSMS returns four individual rows with the correct details. I have read somewhere about EK and problems with optimization when there are no identity column. But - is there anyway to alter the below code to force EK to read all records with all details?
public List<vs_transactions> GetTransactionList(int cID)
{
using (StagingDataEntities db = new StagingDataEntities())
{
var res = from trans in db.vs_transactions
where trans.CreditID == cID
orderby trans.ActionDate descending
select trans;
return res.ToList();
}
}
Found the solution :) MergeOption.NoTracking
public List<vs_transactions> GetTransactionList(int cID)
{
db.vs_transactions.MergeOption = MergeOption.NoTracking;
using (StagingDataEntities db = new StagingDataEntities())
{
var res = from trans in db.vs_transactions
where trans.CreditID == cID
orderby trans.ActionDate descending
select trans;
return res.ToList();
}
}
I am simply trying to derive an array[] using the following Linq query with EFF and Mysql:
DM_ItemGroup[] array =
(from item_grp in DbContext.hexa_item_group
join item_btn in DbContext.hexa_button
on item_grp.GroupID equals item_btn.ButtonID
where item_btn.ButtonType.Equals("G", StringComparison.Ordinal)
select new DM_ItemGroup
{
GroupID = SqlFunctions.StringConvert((decimal)item_grp.GroupID),
GroupName = item_grp.GroupName,
ButtonID = item_btn.ButtonID,
Default_TaxId = item_grp.Default_TaxId,
Out_Of_Sales = item_grp.Out_Of_Sales,
Sales_Seq = item_grp.Sales_Seq,
DataModel_Button = new DM_Button(),
}).ToArray<DM_ItemGroup>();
I initially tried .ToString() but it gave an exception. After trying SqlFunctions.StringConvert I am getting the following error:-
The specified method 'System.String StringConvert(System.Nullable`1[System.Decimal])'
on the type 'System.Data.Objects.SqlClient.SqlFunctions'
cannot be translated into a LINQ to Entities store expression.
How to convert the GroupID (which is a Int in my Table) to String (which is required by my DataModel)?
Thanks for down voting a perfectly legitimate question.Wish someone had answered the question with equal promptness.
I found the solution to my problem which is as follows:-
using (HexaEntities hh=new HexaEntities())
{
var cc = hh.hexa_item_group.ToDictionary(k => k.GroupID, k => k);
var lst = from l in cc
orderby l.Key
select new DM_ItemGroup {GroupID = l.Key.ToString(), GroupName = l.Value.GroupName, Default_TaxId=l.Value.Default_TaxId,ButtonID=l.Value.ButtonID.Value,Out_Of_Sales=l.Value.Out_Of_Sales,Sales_Seq=l.Value.Sales_Seq };
AllRecords = lst.ToList<DM_ItemGroup>();
}
I am trying to add a note to my event object. I am getting an error using this code
Note noteToAdd = new Note { State = State.Added, NoteText = note };
Patient patient = context.Patients.Find(patientId);
patient.State = State.Modified;
patient.MobilePatient.State = State.Modified;
patient.MobilePatient.MCalmEvents.Find(e => e.Id == eventid).Note = noteToAdd;
context.ApplyStateChanges();
Is there a better way to do it using Linq To Entity?
The error that I am having is :
{"Invalid column name 'Note_Id'."}
and the SQl that is being generated is a SELECT instead of INSERT.
Thank you
but your map shows a one-to-many relation between Note and Event...
all of your code remain as they are, but instead of this line :
patient.MobilePatient.MCalmEvents.Find(e => e.Id == eventid).Note = noteToAdd;
replace these lines:
noteToAdd.EventID = oEvent.ID; // replace field names, to exactly what they are;
context.Note.Add(noteToAdd);
var oEvent = patient.MobilePatient.MCalmEvents.Find(e => e.Id == eventid);
oEvent.NoteID = noteToAdd.ID; // replace field names, to exactly what they are;
also i think if you don`t write these two:
var oEvent = patient.MobilePatient.MCalmEvents.Find(e => e.Id == eventid);
oEvent.NoteID = noteToAdd.ID; // replace field names, to exactly what they are;
there is not any problem, i`m not sure
According to your map, Event entity has a list of Note as navigation property, and i think you should add to this collection instead, what you write in this line:
patient.MobilePatient.MCalmEvents.Find(e => e.Id == eventid).Note = noteToAdd;
i think should be like this:
patient.MobilePatient.MCalmEvents.Find(e => e.Id == eventid).Add(noteToAdd);
in addition, what kind of error you get ? can you explain your error ?
are sure there is no add method on Event navigation property
why don`t you try to add note from context directly? like:
context.Note.Add(noteToAdd);
How to select country name from auto-complete drop down list?
Please provide suggestion with code for Google search so that i can understand.
If your dropdown is editable you can directly type the values using send keys, else you need to simulate the Arrow down key actions as you needed. But it not wise once, because if new values are added in the drop down(Anyway in this case, there will be fixed because the number of countries is a constant),then it will get messed.
driver.findElement(locator).sendKeys(countryName , Keys.TAB);
or
driver.findElement(locator).sendKeys(Keys.DOWN);
Try the following code:
WebElement dropdown = driver.findElement(By.....);
Select dropdownSelect = new Select(dropdown);
dropdownSelect.selectByVisibleText(itemStr) or selectByValue(value);
Link : http://www.mythoughts.co.in/2012/05/getting-google-search-auto-suggestions.html#.Ul-lJdi1Zbc
#Test
public void SearchSuggestion() {
driver.get("http://google.com");
driver.findElement(By.id("gbqfq")).sendKeys("vam");
driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);
WebElement table = driver.findElement(By.className("gssb_m"));
List<webelement> rows = table.findElements(By.tagName("tr"));
Iterator<webelement> i = rows.iterator();
System.out.println("-----------------------------------------");
while(i.hasNext()) {
WebElement row = i.next();
List<webelement> columns = row.findElements(By.tagName("td"));
Iterator<webelement> j = columns.iterator();
while(j.hasNext()) {
WebElement column = j.next();
System.out.println(column.getText());
}
System.out.println("");
System.out.println("-----------------------------------------");
}
}
}
driver.findElement(By.id("your searchBox")).sendKeys("your partial keyword");
Thread.sleep(3000);
List <WebElement> listItems = driver.findElements(By.xpath("your list item locator"));
listItems.get(0).click();
driver.findElement(By.id("your searchButton")).click()
I have the following model
The first step is to select all the ProductionBlock with
var blocks = context.ProductionBlocks;
How can I combine the ProductionLog that has no end time with the ProductionBlock?
I tried to do it using a reverse lookup like
var blocks = context
.ProductionLogs
.Include("FK_ProductionLog_ProductionBlock")
.Where(log => log.EndTime == null).Select(log => log.ProductionBlock)
.Union(context.ProductionBlocks);
But the blocks don't contains any ProductionLogs. How can I achieve that?
Let me know if i am off base, but you would want.
var logs = (
from pl in context.ProductionLogs.Include("ProductionBlock")
where pl.EndTime == null
select pl);
You would then have a list of logs and blocks.
var blocks = logs.SelectMany(x=>x.ProductionBlock)