I'm trying to insert data into a MariaDB with EntityFrameWork 5 in Visual Studio. I created the database on the server itself and imported the model in Visual Studio. I'm using three tables and they are linked.
A draing table, project table and tag table.
Entities are: drawing (many---1) project (1---many) tag.
For the insert I use the code below. But it throws an DbUpdateEntityException who tells that he can't match the key between the drawing and project table because two or more primary keys are the same. I use a specific primary key for dat drawing which is definitely not the same with a other object in the table. The other primary keys are AUTO_INCREMENT So I guess that it tries to insert a new project but with the same project number which don't work but I don't really get it why it is doing this.
DateTime aktuellesDatum = DateTime.Now;
using (DMSContext db = new DMSContext())
{
foreach (ZeichnungInDB zeichnungInDB in zeichnungen)
{
zeichnungInDB.Volante_Index = getVolCountByDrawingNumber(zeichnungInDB.Zeichnungsnummer) + 1;
var zeichnung = new zeichnung()
{
Zeichnung_ID = zeichnungInDB.Dateiname + "_" + zeichnungInDB.Index + "_VOL_" + zeichnungInDB.Volante_Index + "_" + aktuellesDatum.ToShortDateString(),
Baugruppe = zeichnungInDB.Baugruppe,
Baugruppe_Hauptzeichnung = zeichnungInDB.Baugruppe_Hauptzeichnung,
Zeichnungsnummer = zeichnungInDB.Zeichnungsnummer,
Index = zeichnungInDB.Index,
Dateiname_Org = zeichnungInDB.Dateiname,
Aenderung_Ext = zeichnungInDB.Aenderung_Ext,
Aenderung_Int = "AE_" + zeichnungInDB.Projektnummer + aktuellesDatum,
Dokumententyp = zeichnungInDB.DokumentenTyp,
Dateiendung = zeichnungInDB.Extension,
Volante_Index = zeichnungInDB.Volante_Index,
MMS_Sachmerkmal = zeichnungInDB.Mms_Sachmerkmal,
Status = zeichnungInDB.Status,
Aenderung_Bemerkung_Txt = zeichnungInDB.Aenderung_Bemerkung_Text,
Einzel_Bemerkung_Txt = zeichnungInDB.Einzel_Bemerkung,
Ahang_Link = zeichnungInDB.Anhang_Link,
Einzel_Link = zeichnungInDB.Einzel_Link,
};
var projekt = new projekt()
{
Projektnummer = zeichnungInDB.Projektnummer,
};
var tag = new tag()
{
Tag1 = zeichnungInDB.Tag,
};
db.zeichnungs.Add(zeichnung);
db.projekts.Add(projekt);
db.tags.Add(tag);
}
try
{
db.SaveChanges();
}
catch (System.Data.Entity.Validation.DbEntityValidationException dbEx)
{
Exception raise = dbEx;
foreach (var validationErrors in dbEx.EntityValidationErrors)
{
foreach (var validationError in validationErrors.ValidationErrors)
{
string message = string.Format("{0}:{1}",
validationErrors.Entry.Entity.ToString(),
validationError.ErrorMessage);
// raise a new exception nesting
// the current instance as InnerException
raise = new InvalidOperationException(message, raise);
}
}
throw raise;
}
}
maybe someone has an idea or a solution where the problem is.
(The "ZeichnungInDB" is an custom object and "zeichnungen" is ObservableCollection)
The other question I have is, I implemented a field for date time which is CURRENT_TIMESTSAMP but it only shows 0000-00-00 00:00:00 why is this?
Are you using fluent API? if you are, you should mark the id's properties as Identity like the example:
Property(p => p.DrawingId).
HasDatabaseGeneratedOption(DatabaseGeneratedOption.Identity);
Or you can mark with an annotation in the primary key of your entities like the example:
public class drawing {
[Key]
[DatabaseGenerated(DatabaseGeneratedOption.Identity)]
public int ind DrawingId {get; set;}
....
}
link:
http://www.opten.ch/blog/2014/03/5/configuring-entity-framework-with-fluent-api/
regards.
Related
I need to modify the UpgradeCode property of the Upgrade MSI table via C#.
This code works ok with other tables' properties, but throws an error when I'm trying to modify these.
using (var database = new Database(TEMPDATABASE, DatabaseOpenMode.Direct))
{
string upgradeCode = Guid.NewGuid().ToString("B").ToUpper();
database.Execute("Update `Upgrade` Set `Upgrade`.`UpgradeCode` = '{0}'", upgradeCode);
}
The error is:
Microsoft.Deployment.WindowsInstaller.InstallerException: 'Function failed during execution.'
I got curious and pillaged github.com - and it giveth the following: Full project - just download it as a whole.
The actual code was (some unicode line feed issues in the file on github.com, I have fixed them up here):
public static void UpdateUpgradeTable(this Database db, Guid upgradeCode)
{
using (View view = db.OpenView("SELECT * FROM `Upgrade`", new object[0]))
{
view.Execute();
using (Record record = view.Fetch())
{
record[1] = upgradeCode.ToString("B").ToUpperInvariant();
view.Replace(record);
}
db.Commit();
}
}
I took the above and made the following mock-up (very ugly, but it worked):
using (Database db = new Database(#"C:\Test.msi", DatabaseOpenMode.Direct))
{
using (View view = db.OpenView("SELECT * FROM `Upgrade`", new object[0]))
{
view.Execute();
using (Record record = view.Fetch())
{
record[1] = "{777888DD-1111-1111-1111-222222222222}";
record[2] = "";
record[3] = "4.0.1";
record[4] = "";
record[5] = "1";
record[6] = "";
record[7] = "WIX_UPGRADE_DETECTED";
view.Replace(record);
}
db.Commit();
using (Record record = view.Fetch())
{
record[1] = "{777888DD-1111-1111-1111-222222222222}";
record[2] = "";
record[3] = "";
record[4] = "4.0.1";
record[5] = "1";
record[6] = "";
record[7] = "WIX_DOWNGRADE_DETECTED";
view.Replace(record);
}
db.Commit();
}
}
The SDK doc says:
UPDATE queries only work on nonprimary key columns.
UpgradeCode is the primary key for the Upgrade table.
I have the problem that I have a MariaDB database with HeidiSQL. There are four tables and im using Linq to insert new data. One of the tables isn´t always necessary. So i marked the column with the foreign key in one of the a other tables for can be NULL. The problem is that when i create the new objects to insert into database it creates the new data in the database but the foreign key in the other table keeps emtpy.
When i undo the Null option in the column and want to insert a standardvalue instead, it throws an UpdateEntityException.
What i should mention is, that i cerated the database first in HeidiSQL and created then the code in Visual Studio with EntityFramework 5.0.
Or might the mistake caused by building and adding the database object in an if-clause?
There are some code examples of my code, i hope it will help.
DateTime aktuellesDatum = DateTime.Now;
int proId = getProjectIdByProjectnumber(zeichnungen[0].Projektnummer);
int tagId = getTagIdByTag(zeichnungen[0].Tag, zeichnungen[0].Projektnummer);
string hauptzeichnung = "";
int gruppeId = -1;
//Noch kein Projekt vorhanden
if(proId == -1)
{
using (DMSContext db = new DMSContext())
{
foreach (ZeichnungInDB zeichnungInDB in zeichnungen)
{
zeichnungInDB.Volante_Index = getVolCountByDrawingNumber(zeichnungInDB.Zeichnungsnummer) + 1;
var zeichnung = new zeichnung()
{
Zeichnung_ID = zeichnungInDB.Dateiname + "_" + zeichnungInDB.Index + "_VOL_" + zeichnungInDB.Volante_Index + "_" + aktuellesDatum.ToShortDateString(),
Zeichnungsnummer = zeichnungInDB.Zeichnungsnummer,
Index = zeichnungInDB.Index,
Zeitstempel = aktuellesDatum,
Dateiname_Org = zeichnungInDB.Dateiname,
Aenderung_Ext = zeichnungInDB.Aenderung_Ext,
Aenderung_Int = "AE_" + zeichnungInDB.Projektnummer + "_" + aktuellesDatum.Year + "-" + aktuellesDatum.Month + "-" + aktuellesDatum.Day + " " + aktuellesDatum.Hour + ":" + aktuellesDatum.Minute,
Dokumententyp = zeichnungInDB.DokumentenTyp,
Dateiendung = zeichnungInDB.Extension,
Volante_Index = zeichnungInDB.Volante_Index,
MMS_Sachmerkmal = zeichnungInDB.Mms_Sachmerkmal,
Status = zeichnungInDB.Status,
Aenderung_Bemerkung_Txt = zeichnungInDB.Aenderung_Bemerkung_Text,
Einzel_Bemerkung_Txt = zeichnungInDB.Einzel_Bemerkung,
Ahang_Link = zeichnungInDB.Anhang_Link,
Einzel_Link = zeichnungInDB.Einzel_Link,
};
db.zeichnungs.Add(zeichnung);
if(zeichnungInDB.Baugruppe_Hauptzeichnung == true)
{
hauptzeichnung = zeichnungInDB.Zeichnungsnummer;
}
}
var projekt = new projekt()
{
Projektnummer = zeichnungen[0].Projektnummer,
};
var tag = new tag()
{
Tag1 = zeichnungen[0].Tag,
};
if (!hauptzeichnung.Equals(""))
{
var baugruppe = new baugruppe
{
Hauptzeichnung = hauptzeichnung,
};
db.baugruppes.Add(baugruppe);
}
db.projekts.Add(projekt);
db.tags.Add(tag);
try
{
db.SaveChanges();
}
catch (System.Data.Entity.Validation.DbEntityValidationException dbEx)
{
Exception raise = dbEx;
foreach (var validationErrors in dbEx.EntityValidationErrors)
{
foreach (var validationError in validationErrors.ValidationErrors)
{
string message = string.Format("{0}:{1}",
validationErrors.Entry.Entity.ToString(),
validationError.ErrorMessage);
// raise a new exception nesting
// the current instance as InnerException
raise = new InvalidOperationException(message, raise);
}
}
throw raise;
}
}
This is only a short e.g. from my code because the whole cs would be to long and nobody would spend the time on so much code.
One other thing i would like to ask is. If the following code works correct for update a string in a field?
private static void updateHauptzeichnung(int baugruppeId, string zeichnungsnummer)
{
using (var context = new DMSContext())
{
var query = context.baugruppes
.Where(b => b.Baugruppe_ID == baugruppeId)
.Select(g => new { g.Hauptzeichnung })
.SingleOrDefault();
if (query != null)
{
query.Hauptzeichnung.Replace(query.Hauptzeichnung, zeichnungsnummer);
}
context.SaveChanges();
}
}
I solved my problem. I changed the foreignkey field from can be NULL to is necessary, added in the foreign table a costum dataset with ID is 0 and I give new data this ID as its foreign ID when they have no offical link to the foreign table. It might not be the best solution, but it fixed my problem.
I want to swap items to re order. Reorder index is primary key so I can not edit it. So what I am doing:
I am searching items with name and cloned it to another object.
I am also searching previous item on that with key found on case 1. and cloned it to an object.
I deleted both the search items from DB.
Insert New replaced item with previous key and change previous cloned item key to a random no. add to DB.
During search when this preivous item through name in loop it key change from clone and add to db.
Its working when First Compile. But when I reorder again in list then it throws error in Conflicting Primary keys in both case Attach() and Remove().
Code is as follows
foreach (var item in items)
{
var task = db.ProjectTasks.Where(wh => wh.ProjectID == item.projectID && wh.TaskDesc==item.taksName).FirstOrDefault();
var oldTask = db.ProjectTasks.Where(wh => wh.ProjectID == item.projectID && wh.TaskID == item.taskID).FirstOrDefault();
if (oldTask != null)
{
//db.ProjectTasks.Attach(oldTask);
db.ProjectTasks.Remove(oldTask);
//db.SaveChanges();
}
// var cloneTask = task; //Cloned task to inser same ater delete
var taskClone1 = new ProjectTask {
ActualManHrs=task.ActualManHrs,
AFDate=task.AFDate,
ASDate=task.ASDate,
ConDate=task.ConDate,
DaysComplete=task.DaysComplete,
DaysRemaining=task.DaysRemaining,
Duration=task.Duration,
DurationActual=task.DurationActual,
EFDate=task.EFDate,
ESDate=task.ESDate,
orderIndex=task.orderIndex,
PercentComplete=task.PercentComplete,
PlannedManHrs=task.PlannedManHrs,
PriorTask=task.PriorTask,
ProjectID=task.ProjectID,
ProjectMaster=task.ProjectMaster,
Remarks=task.Remarks,
ResourceCenter=task.ResourceCenter,
TaskDesc=task.TaskDesc,
TaskGroup=task.TaskGroup,
TaskID=item.taskID,
TaskStatus=task.TaskStatus,
WorkingDays=task.WorkingDays
};
var swap1 = new List<ProjectTask>();
swap1.Add(taskClone1);
ProjectTask oldTaskDetails = null;
if (oldTask != null)
{
oldTaskDetails = new ProjectTask
{
ActualManHrs = oldTask.ActualManHrs,
AFDate = oldTask.AFDate,
ASDate = oldTask.ASDate,
ConDate = oldTask.ConDate,
DaysComplete = oldTask.DaysComplete,
DaysRemaining = oldTask.DaysRemaining,
Duration = oldTask.Duration,
DurationActual = oldTask.DurationActual,
EFDate = oldTask.EFDate,
ESDate = oldTask.ESDate,
orderIndex = oldTask.orderIndex,
PercentComplete = oldTask.PercentComplete,
PlannedManHrs = oldTask.PlannedManHrs,
PriorTask = oldTask.PriorTask,
ProjectID = oldTask.ProjectID,
ProjectMaster = oldTask.ProjectMaster,
Remarks = oldTask.Remarks,
ResourceCenter = oldTask.ResourceCenter,
TaskDesc = oldTask.TaskDesc,
TaskGroup = oldTask.TaskGroup,
TaskID = oldTask.TaskID,
TaskStatus = oldTask.TaskStatus,
WorkingDays = oldTask.WorkingDays
};
}
var swap2 = new List<ProjectTask>();
swap2.Add(oldTaskDetails);
if(task!=null) //Check Nll or not
{
db.ProjectTasks.Remove(task); //2nd time on ward Primary key voilation
db.SaveChanges();
db.ProjectTasks.AddRange(swap1); //2nd time on ward Primary key voilation
if (oldTaskDetails != null)
{
oldTaskDetails.TaskID = Guid.NewGuid().ToString().Substring(0, 4);
db.ProjectTasks.AddRange(swap2);
}
}
//db.SaveChanges();
}
The thing is that SQL server autoincrements the primary keys even though you are deleting records. Check this post, it will help you out in how to reset back those primary keys. That's why you are getting exceptions regarding primary key conflicts.
However, that is a short term solution and I would not recommend it. I would definitely redesign your solution. At the end, you just want a Display Order for the items that you are swapping.
I would create a new column in the table called DisplayOrder that would add values from 1 to n every time a record is added. And, then I would just call OrderBy(i => i.DisplayOrder). And, at the end, if you really need to swap values (change their order), I would create a new function called SwapValues(ProjectTaskA, projectTaskB) that would change their display order. Or, if you really want to make it even better, you could create something called SwapValues(ProjectTask, moveDown, numberOfSteps) with the object in question, the number of steps that would have to go until finding the object to be swapped with and a direction, up or down.
These are just a couple of ideas of what you could do. I hope they help you.
After 4 days of fighting with Primery Key voilation... I found simple solution
var projectID = items.FirstOrDefault().projectID;
var group=items.FirstOrDefault().sourceGroup;
//Loop through changable item
foreach(var item in items)
{
checkPrimeryKey: //return back after changin duplicate item taskID
var checkDuplicate = db.ProjectTasks.Where(wh => wh.ProjectID == projectID && wh.TaskID == item.taskID).FirstOrDefault();
if (checkDuplicate == null) //If not Duplicate found
{
string sql = "update ProjectTasks set taskID='" + item.taskID + "' where projectID=" + projectID + " and TaskDesc='" + item.taksName + "'";
db.Database.ExecuteSqlCommand(sql);
}
else //If duplicate found change its task ID and return back to Step:1
{
string sql = "update ProjectTasks set taskID='" + Guid.NewGuid().ToString().Substring(0, 4) + "' where projectID=" + projectID + " and TaskDesc='" + checkDuplicate.TaskDesc + "'";
db.Database.ExecuteSqlCommand(sql);
goto checkPrimeryKey;
}
}
db.SaveChanges();
I have been struggling with this problem for some time now and am not able to resolve this. Have read multiple posts and tried several different solutions but nothing has worked. Now I feel like I have come to a stop and really need help with this.
I am using EF 5+ with an DB first and edmx file. I have 3 different tables in my DB:
1. Settlement
2. Cost
3. Shift
Settlement has a collection of both Cost and Shift (with a link table) connected by Association in my edmx file.
I need to insert a new Settlement in my db with a reference to an already existing Cost and Shift collections.
Shifts and Costs included in my Settlement entity I am trying to insert contains all there related data and none of those are modified in any way (same as I retrieved from db).
Here in my method of inserting the entity into my db.
public bool CreateSettlement(Settlement settlement)
{
bool _success;
var _context = new EtaxiEnteties();// ObjectFactory.Get<IETaxiEntitiesContext>();
try
{
var _newSettlement = new Settlement
{
CreateDate = settlement.CreateDate,
Driver = settlement.Driver,
DriverID = settlement.DriverID,
Car = settlement.Car,
CarID = settlement.CarID,
DocPath = settlement.DocPath
};
foreach (var _shift in settlement.Shifts)
{
//var _sh = _context.Shifts.Find(_shift.ShiftID);
//_context.Entry(_sh).CurrentValues.SetValues(_shift);
_newSettlement.Shifts.Add(_shift);
}
foreach (var _cost in settlement.Costs)
{
////var _sh = _context.Costs.Find(_cost.CostID);
////_context.Entry(_sh).CurrentValues.SetValues(_cost);
_newSettlement.Costs.Add(_cost);
}
_context.Settlements.Add(_newSettlement);
_success = _context.SaveChanges() > 0;
}
catch (Exception ex)
{
throw new Exception(ex.Message);
}
return _success;
}
Any help on the issue would be MUCH appreciated.
Here is how I am adding the Cost and Shift to my collection:
I create a Settlement in page:
_settlement = new Settlement
{
CreateDate = DateTime.Now,
Driver = _driver,
DriverID = _driver.DriverID,
Car = _car,
CarID = _car.CarID,
DocPath = _path
};
then when I create a pdf file with selected rows from 2 separated grid views:
foreach (GridDataItem _selectedRow in gwShifts.MasterTableView.Items)
{
if (_selectedRow.Selected)
{
var _shift =
_diaryRepository.GetShiftByID((int) _selectedRow.GetDataKeyValue("ShiftID")).FirstOrDefault();
if (_shift != null)
{
_settlement.Shifts.Add(_shift);
_settlementData.Shifts.Add(_shift);
_settlementData.SplitPercentace = GetTemplateValue(_selectedRow, "lblSplit");
_settlementData.SettlementAmount = GetTemplateValue(_selectedRow, "lblSettlementAmount");
if (_settlementData.Shifts != null)
{
_tableShifts.AddCell(
new PdfPCell(
new Phrase(
_settlementData.Shifts.FirstOrDefault().ShiftDate.ToShortDateString(),
_bodyFont)) {Border = 0});
_tableShifts.AddCell(
new PdfPCell(
new Phrase(
string.Format("{0:c}", _settlementData.Shifts.FirstOrDefault().GrossAmount),
_bodyFont)) {Border = 0});
_tableShifts.AddCell(
new PdfPCell(
new Phrase(
string.Format("{0:c}", _settlementData.Shifts.FirstOrDefault().MoneyAmount),
_bodyFont)) {Border = 0});
_tableShifts.AddCell(new PdfPCell(new Phrase(_settlementData.SplitPercentace, _bodyFont))
{Border = 0});
_tableShifts.AddCell(
new PdfPCell(new Phrase(_settlementData.SettlementAmount, _boldTableFont))
{Border = 0});
_totalAmount.AddRange(new[]
{
Convert.ToInt32(
_settlementData.SettlementAmount.Replace(".", "").
Replace(",", "").Replace("kr", ""))
});
_settlementData.Shifts.Remove(_shift);
}
}
}
}
var _summaryCell =
new PdfPCell(new Phrase("Upphæð: " + string.Format("{0:c}", _totalAmount.Sum()), _boldTableFont))
{
Border = 0,
Colspan = 5,
HorizontalAlignment = Element.ALIGN_RIGHT,
Padding = 5,
BorderWidthTop = 1
};
_tableShifts.AddCell(_summaryCell);
if (_totalAmount.Count != 0)
_totalAmount.Clear();
}
there you see how I add the Shift to this Settlement entity:
var _shift =
_diaryRepository.GetShiftByID((int) _selectedRow.GetDataKeyValue("ShiftID")).FirstOrDefault();
if (_shift != null)
{
_settlement.Shifts.Add(_shift);
then I send this to the reporistory (see method above)
if(_driverRepository.CreateSettlement(_settlement))
{
SetMessage("Uppgjör hefur verið skapað og sent bílstjóra ef e-póstur er skráður á viðkomandi bílstjóra.", "Uppgjör skapað");
pnlSettlement.Visible = false;
pnlDocCreation.Visible = false;
pnlResult.Visible = false;
}
I also tried to simply add param settlement directly to the context but got similar error.
I think this has to do with how you're populating the Shifts and Costs collection. You're trying to add already created records (i.e. they already have their primary key values set) to be saved with the new Settlement entity, but I believe that Entity Framework isn't trying to create new ones that are linked to your new Settlement entity but rather save them to the table as is. In such a case you would indeed have a situation where multiple entities have the same primary key.
I would try the following (I'll show you using the Shifts loop only, but you should be able to apply it to the Costs loop as well):
foreach (var _shift in settlement.Shifts)
{
var newShift = new Shift { /*Copy all of the values from _shift here*/ };
_newSettlement.Shifts.Add(_shift);
context.Shifts.Add(newShift);
}
If that doesn't work I would suggest debugging Costs and Shifts to make sure that you don't have any duplicates in those collections.
If you don't want new Shifts & Costs then I can only assume you need to repoint the existing ones to the new Settlement
foreach (var shift in settlement.Shifts)
{
//either
shift.Settlement = newSettlement;
//or
shift.SettlementId = newSettlement.SettlementId;
//depending on your object model
}
I've just realised that I have misunderstood the question. There are 2 additional tables not shown in the diagram (Costs & Shifts). The problem is trying to create SettlementCost and SettlementShift entities that connect Settlement to Costs\Shifts.
OK, came up with a "ugly" solution on this..but it is resolved.
Changed the Model to be one(Settlement) -> many(Shift or Cost) relationship.
I create a new Settlement and save this one to the DB.
Retrieve each Shift and Cost from the DB update SettlementID on each and save these to the DB.
try
{
var _newSettlement = new Settlement
{
CreateDate = settlement.CreateDate,
DriverID = settlement.DriverID,
CarID = settlement.CarID,
DocPath = settlement.DocPath
};
Add(_newSettlement);
_success = SaveWithSuccess() > 0;
var _settlement = GetAll().FirstOrDefault(x => x.SettlementID == _newSettlement.SettlementID);
if (_success)
{
foreach (var _shift in settlement.Shifts)
{
var _sh = _diaryRepository.GetShiftByID(_shift.ShiftID).FirstOrDefault();
_sh.SettlementID = _settlement.SettlementID;
_diaryRepository.UpdateShift(_sh);
}
foreach (var _cost in settlement.Costs)
{
var _ch = _costRepository.GetCostByID(_cost.CostID);
_ch.SettlementID = _settlement.SettlementID;
_costRepository.UpdateCost(_ch);
}
}
}
not a pretty one, but it resolves the problem.
I am not concerned about the DB request load..it will not be that high in this case.
I would think there is a nicer solution to this but I was not able to find it at this time.
Thanks for all your efforts to help :)
I want to update my model through a class and not a form in ASP.Net MVC 2.
[AcceptVerbs(HttpVerbs.Post)]
public ActionResult Index(string wo_number)
{
WorkOrder wo = GetWorkOrder(wo_number);
UpdateModel(wo);
camprintRepository.Save();
return RedirectToAction("Details", new { wo_number = wo_number });
}
I'm pulling the information from an outside source and I want it to update the entities in my applications database.
public WorkOrder GetWorkOrder (string wo_number)
{
UniFile uFile = uSession.CreateUniFile("WO");
uFile.RecordID = wo_number;
WO wo = new WO();
wo.wo_id = wo_number;
wo.sales_product_code = uFile.ReadNamedField("Sales_Code").ToString();
wo.description = uFile.ReadNamedField("P_Desc").ToString();
wo.part_number = uFile.ReadNamedField("Desc").ToString();
wo.work_order_quantity = uFile.ReadNamedField("Qty_To_Mfg").ToString();
wo.sales_order_quantity = uFile.ReadNamedField("Sod_Qty").ToString();
GetWorkOrderOper(wo);
}
I am using LINQ to SQL and as you can see there are some child objects that branch off from each workorder.
public void GetWorkOrderOper(WorkOrder wo)
{
UniFile uFile = uSession.CreateUniFile("WPO");
string key = wo.wo_id + "*" + wo.first_routing_sequence;
while(key != wo.wo_id + "*")
{
uFile.RecordID = key;
WPO wpo = new WPO();
wpo.wpo_id = key;
wpo.next_sequence_number = uFile.ReadNamedField("Next_Seq").ToString();
wpo.run_hours = uFile.ReadNamedField("Plan_Run_Lbr_Time").ToString();
key = wo.wo_id + "*" + wpo.next_sequence_number;
wo.WPOs.Add(wpo);
}
}
This is not updating the models and I'm not sure why. Any help would be greatly appreciated
Seems like there is no SubmitChanges? Or is that in your UpdateModel?
Another cause might be no primary key in your underlying table