a quick question. Am I doing right ?
Report report1 = new Report();
report1.setBigDecimalValue( BigDecimal.valueOf(Double.valueOf(10.3)) );
Report report2 = new Report();
report1.setBigDecimalValue( BigDecimal.valueOf(Double.valueOf(57.3)) );
List<Report> reports = new ArrayList<>();
reports.add(report1);
reports.add(report2);
BigDecimal totalPax = reports.stream().map(Report::getBigDecimalValue).reduce(BigDecimal.ZERO, BigDecimal::add);
I am getting below compilation error:
Cannot resolve method 'add'
Related
OrientDB question...
Does anyone know how I can get the recordId after an insert:
db.save(person)
I tried below on the Person POJO:
#Id
private Object id;
but the id field was null after the save. I've googled and googled to no avail. I just need to insert an object, then get the recordid that orientdb generates.
Define field in pojo:
#Id
private Object rid;
public Object getRid() {
return rid;
}
When save:
YourClass proxy = db.save(yourClassInstance);
Object rid = proxy.getRid();
I got it to work using ODocuments instead of POJOs (which works for my project). Code sample:
ODatabaseDocumentTx db = null;
ODocument doc = null;
db = new ODatabaseDocumentTx("local:" + System.getProperty("user.home") + "/testDB");
db.create();
doc = new ODocument("Person");
doc.field("name", "Peter");
doc.save();
String rid = doc.getIdentity().toString();
List<ODocument> results = db.query(new OSQLSynchQuery<ODocument>("select from " + rid));
for (ODocument aDoc : results) {
System.out.println(aDoc.field("name"));
}
db.close();
It's just simple here is the code:
//insertquery will be the sql statement you want to insert
ODocument result=db.command(new OCommandSQL(insertquery)).execute();
System.out.println(result.field("#rid"));
Alternatively you can make use of getRecordByUserObject() of OObjectDatabaseTx,
OObjectDatabaseTx db = new OObjectDatabaseTx("local:" + System.getProperty("user.home") + "/testDB");
ODocument oDocument = db.getRecordByUserObject( person, true );
oDocument.save();
String rid = oDocument.getIdentity().toString();
If you already have access to your proxy object from the save, you can totally do a cool cast on it to get the underlying ODocument object which has a record ID (Identity).
Person proxyPerson = db.save(person);
ODocument oDocument = ((OObjectProxyMethodHandler)((ProxyObject)proxyPerson).getHandler()).getDoc();
person.setId(oDocument.getIdentity().toString());
Tool: Visual Studio 2010
Language: C#
I have just started learning Entity Framework,I'm stuck in a problem,whenver I used Code#1 it works fine but whenever I use CODE#2,I get error (posted below)
Title: InvalidOperationException was unhandled by user code
Error Message
"The EntityCollection has already been initialized. The InitializeRelatedCollection method should only be called to initialize a new EntityCollection during deserialization of an object graph."
//SchoolModel.Designer.cs
public EntityCollection<Course> Courses
{
get
{ //Blah blah code }
set
{
if ((value != null))
{//Below statement is pointed by Visual Studio as Exception Thrower
((IEntityWithRelationships)this).RelationshipManager.InitializeRelatedCollection<Course>("SchoolModel.CourseInstructor", "Course", value);
}
}
}
CODE# 1:
List<string> list = new List<string>();
var prs = new Person();
using (var myEntity = new SchoolEntities())
{
var result = myEntity.People;
foreach (var ppl in result)
{
list.Add(ppl.PersonID+","+ppl.FirstMidName);
}
}
CODE# 2:
List<string> list = new List<string>();
List<Person> prsList = new List<Person>();//when using this list,problem started
var prs = new Person();
using (var myEntity = new SchoolEntities())
{
var result = myEntity.People;
foreach (var ppl in result)
{
list.Add(ppl.PersonID+","+ppl.FirstMidName);
//New code which raised exceptions
prs.PersonID = ppl.PersonID;
prs.FirstMidName = ppl.FirstMidName;
prs.LastName = ppl.LastName;
prs.Courses = ppl.Courses;
prsList.Add(prs);
//New code end
}
}
Database Diagram:
Entity Diagram:
P.S:
I followed EF tutorials at http://www.asp.net/web-forms/tutorials/getting-started-with-ef/the-entity-framework-and-aspnet-getting-started-part-3, then deviated and started to play with it :)
I did find some related error questions,but my scenario is different.
You should not set an EntityCollection, as you do in prs.Courses = ppl.Courses. The collection has already been initialized (as per exception). You only modify it by Adding Course instances to it.
Can you try by moving the initialization of prs inside of the foreach loop.
I am working on Unit testing the MVC3 site using NUnit, MvcContrib.TestHelper package but I am facing the exception "Object reference not set to an instance of an object" when my test method accesses the controller having TryUpdateModel. I dont know what to do to pass the test. please help me in this.
I am also giving a code for that :
Action from Controller which test method calls, is given below :
public JsonResult AddPatient()
{
bool returnStatus;
string returnErrorMessage;
List<string> returnMessage;
PatientBLL patientBLL = new PatientBLL();
Models.PatientViewModel patientViewModel = new Models.PatientViewModel();
TryUpdateModel(patientViewModel);
Patient patient = patientBLL.AddPatient(
patientViewModel,
out returnMessage,
out returnStatus,
out returnErrorMessage);
patientViewModel.UpdateViewModel(patient, typeof(Patient).GetProperties());
patientViewModel.ReturnMessage = returnMessage;
patientViewModel.ReturnStatus = returnStatus;
return Json(patientViewModel);
}
and the test method which calls the above action is given below :
[Test]
public void Test_AddPatient()
{
TestControllerBuilder builder = new TestControllerBuilder();
string uniquePatientKey = GenerateUniqueID();
builder.Form["MedicalID"] = uniquePatientKey;
builder.Form["SocialSecurityNumber"] = uniquePatientKey;
builder.Form["FirstName"] = "Khushi";
builder.Form["LastName"] = "Maahi";
builder.Form["AddressLine1"] = "ABCD";
builder.Form["AddressLine2"] = "Technologies";
builder.Form["City"] = "OOna";
builder.Form["State"] = "UP";
builder.Form["ZipCode"] = "98456-7329";
builder.Form["PhoneNumber"] = "(425)882-8080";
builder.Form["DateOfBirth"] = "10/28/1987";
builder.Form["PatientDateOfBirth"] = "10/28/1987";
builder.Form["EffectiveDate"] = "01/01/1995";
builder.Form["PatientEffectiveDate"] = "01/01/1995";
PatientController patientController = builder.CreateController<PatientController>();
JsonResult jsonResult = (JsonResult)patientController.AddPatient();
dynamic jsonData = jsonResult.Data;
string jsonMessage=Convert.ToString(jsonData.ReturnMessage);
Assert.AreEqual(jsonData.ReturnStatus, true );
Assert.Greater(jsonData.PatientID, 0);
}
Please give me the solution for my probelm.
You have a null somewhere in patientViewModel. Can you post that type here? This could be a problem with mixing models and view models.
I have an entity called Invoice and an entity called InvoiceItem.
There is a one to many relationship called new_invoice_invoiceitem.
There is a LookupAttribute in InvoiceItem called new_parent_invoice_invoiceitem.
I am trying to retrieve the InvoiceItems that are related to the Invoice with a particular ID using the following code:
QueryExpression query = new QueryExpression();
query.EntityName = "new_invoiceitem";
query.ColumnSet = new AllColumns();
ConditionExpression condition = new ConditionExpression();
condition.AttributeName = "new_parent_invoice_invoiceitem";
condition.Values = new object [] { new Guid("fe1009cc-e034-49d5-bc59-ab4c3091a6f9") };
condition.Operator = ConditionOperator.Equal;
FilterExpression filter = new FilterExpression();
filter.AddCondition(condition);
query.Criteria = filter;
RetrieveMultipleRequest request = new RetrieveMultipleRequest();
request.Query = query;
RetrieveMultipleResponse response = (RetrieveMultipleResponse)crmService.Execute(request);
BusinessEntityCollection bec = response.BusinessEntityCollection;
The code runs without errors but the BusinessEntityCollection is always empty even though there are records in Dynamics.
Any idea what I'm doing wrong?
Thanks,
David
Try setting request.ReturnDynamicEntities = true
private Boolean Saveuser(bool isNew)
{
tb_User user = new tb_User();
user.User_Name = txtUserName.Text.Trim();
user.User_LoginName = txtLoginName.Text;
user.User_Password = txtPassord.Text;
user.User_ModifiedBy = clsGlobalVariable.strusername;
user.User_Modified = DateTime.Now;
user.User_IsDeleted = false;
user.User_IsUpdated = true;
user.User_UserGroup = "";
user.User_UserType = "";
user.User_WarehouseCode = "";
user.SetIsNew(isNew);
user.Save();
}
when I try to insert new user using above coding, it is worik, but try to update existing user by passing isNew (false). It is not working, when I trace inside activerecord.cs, the dirty column count is always 0 for both new and update. How can I update the existing record?
Please answer for me?
Thanks.
You should
Get the record
Update record
Save
User u = User.FetchByID(2345);
u.User_Name = "blablabla";
//other User object modifications...
u.Save();