Search Results

Search found 6 results on 1 pages for 'jslatts'.

Page 1/1 | 1 

  • pscp.exe (Putty SCP) ignoring preserve attributes flag

    - by jslatts
    I am trying to scp files from a windows server to a linux server with the original time and dates intact. When running the command: pscp.exe -p C:\temp\somefile.txt user@server:/temp/ The file on the server always has the date/time of the transfer, not the original file. Putty SCP seems to be completely ignoring the preserve attributes flag. Anyone experienced this before and/or have a solution?

    Read the article

  • Correct way to edit and update complex viewmodel objects using asp.net-mvc2 and entity framework

    - by jslatts
    I have a table in my database with a one to many relationship to another table: ParentObject ID Name Description ChildObject ID Name Description ParentObjectID AnotherObjectID The objects are mapped into Entity Framework and exposed through a data access class. It seemed like ViewModels are recommended when the data to be displayed greatly differs from the domain object, so I created a ViewModel as follows: public class ViewModel { public IList<ParentObject> ParentObjects { get; set; } public ParentObject selectedObject { get; set; } public IList<ChildObject> ChildObjects { get; set; } } I have a view that displays a list of ParentObjects and when clicked will allow a ChildObject to be modified saved. <% using (Html.BeginForm()) { %> <table> <% foreach (var parent in Model.ParentObjects) { %> <tr> <td> ObjectID [<%= Html.Encode(parent.ID)%>] </td> <td> <%= Html.Encode(parent.Name)%> </td> <td> <%= Html.Encode(parent.Description)%> </td> </tr> <% } %> </table> <% if (Model.ParentObject != null) { %> <div> Name:<br /> <%= Html.TextBoxFor(model => model.ParentObject.Name) %> <%= Html.ValidationMessageFor(model => model.ParentObject.Name, "*")%> </div> <div> Description:<br /> <%= Html.TextBoxFor(model => model.ParentObject.Description) %> <%= Html.ValidationMessageFor(model => model.ParentObject.Description, "*")%> </div> <div> Child Objects </div> <% for (int i = 0; i < Model.ParentObject.ChildObjects.Count(); i++) { %> <div> <%= Html.DisplayTextFor(sd => sd.ChildObjects[i].Name) %> </div> <div> <%= Html.HiddenFor(sd => sd.ChildObjects[i].ID )%> <%= Html.TextBoxFor( sd => sd.ChildObjects[i].Description) %> <%= Html.ValidationMessageFor(sd => sd.ChildObjects[i].Description, "*") %> </div> <% } } } %> This all works fine. My question is around the best way to update the EF objects and persist the changes back to the database. I initially tried: [HttpPost] public ActionResult Edit(ViewModel viewModel) { ParentObject parent = myRepository.GetParentObjectByID(viewModel.SelectedObject.ID); if ((!ModelState.IsValid) || !TryUpdateModel(parent, "SelectedObject", new[] { "Name", "Description" })) { || !TryUpdateModel(parent.ChildObjects, "ChildObjects", new[] { "Name", "Description" })) { //Code to handle failure and return the current model snipped return View(viewModel); } myRepository.Save(); return RedirectToAction("Edit"); } When I try to save a change to the child object, I get this exception: Entities in 'MyEntities.ChildObject' participate in the 'FK_ChildObject_AnotherObject' relationship. 0 related 'AnotherObject' were found. 1 'AnotherObject' is expected. Investigation on StackOverflow and generally googling led me to this blog post that seems to describe my problem: TryUpdateModel() does not correctly handle nested collections. Apparently, (and stepping through the debugger confirms this) it creates a new ChildObject instead of associating with the EF objects from my instantiated context. My hacky work around is this: if (viewModel.ChildObjects.Count > 0) { foreach (ChildObject modelChildObject in viewModel.ChildObjects) { ChildObject childToUpdate = ParentObject.ChildObject.Where(a => a.ID == modelChildObject.ID).First(); childToUpdate.Name = modelChildObject.Name; } } This seems to work fine. My question to you good folks: Is there correct way to do this? I tried following the suggestion for making a custom model binder per the blog link I posted above but it didn't work (there was an issue with reflection) and I needed to get something going ASAP. PS - I tried to cleanup the code to hide specific information, so beware I may have hosed something up. I mainly just want to know if other people have solved this problem. Thanks!

    Read the article

  • Using Visual Studio Intellisense for building jQuery selector strings

    - by jslatts
    This is a minor issue, but one I find myself running into: When I am using jQuery in Visual Studio 2010, I find myself frequently typing: $(#S using Intellisense to find the SomeID object ID: $(#SomeID).click( function() { etc.. }) then going back and adding quotes: $('#SomeID').click( function() { etc.. }) I find it annoying that if I add the quote first, Visual Studio goes into string mode and I lose Intellisense for finding the object's ID or class. Am I doing it wrong?

    Read the article

  • Retrieving/Updating Entity Framework POCO objects that already exist in the ObjectContext

    - by jslatts
    I have a project using Entity Framework 4.0 with POCOs (data is stored in SQL DB, lazyloading is enabled) as follows: public class ParentObject { public int ID {get; set;} public virtual List<ChildObject> children {get; set;} } public class ChildObject { public int ID {get; set;} public int ChildRoleID {get; set;} public int ParentID {get; set;} public virtual ParentObject Parent {get; set;} public virtual ChildRoleObject ChildRole {get; set;} } public class ChildRoleObject { public int ID {get; set;} public string Name {get; set;} public virtual List<ChildObject> children {get; set;} } I want to create a new ChildObject, assign it a role, then add it to an existing ParentObject. Afterwards, I want to send the new ChildObject to the caller. The code below works fine until it tries to get the object back from the database. The newChildObjectInstance only has the ChildRoleID set and does not contain a reference to the actual ChildRole object. I try and pull the new instance back out of the database in order to populate the ChildRole property. Unfortunately, in this case, instead of creating a new instance of ChildObject and assigning it to retreivedChildObject, EF finds the existing ChildObject in the context and returns the in-memory instance, with a null ChildRole property. public ChildObject CreateNewChild(int id, int roleID) { SomeObjectContext myRepository = new SomeObjectContext(); ParentObject parentObjectInstance = myRepository.GetParentObject(id); ChildObject newChildObjectInstance = new ChildObject() { ParentObject = parentObjectInstance, ParentID = parentObjectInstance.ID, ChildRoleID = roleID }; parentObjectInstance.children.Add(newChildObjectInstance); myRepository.Save(); ChildObject retreivedChildObject = myRepository.GetChildObject(newChildObjectInstance.ID); string assignedRoleName = retreivedChildObject.ChildRole.Name; //Throws exception, ChildRole is null return retreivedChildObject; } I have tried setting MergeOptions to Overwrite, calling ObjectContext.Refresh() and ObjectContext.DetectChanges() to no avail... I suspect this is related to the proxy objects that EF injects when working with POCOs. Has anyone run into this issue before? If so, what was the solution?

    Read the article

  • Conditionally embed ASP.NET MVC2 Views as resources during build in Visual Studio 2010

    - by jslatts
    I have a ASP.NET MVC2 project in VS2010 that can be deployed in two modes: standalone or plugin. In standalone mode, the views should live outside the compiled assembly as .aspx files (the default setup). In plugin mode, the views are switched (currently by hand) to embedded resources and the entire assembly is dropped into a host project folder. Currently, this requires the developer to go through each view and switch it from Build Action: "Content" to "Embedded Resource" and vice versa. I would like to create a new solution configuration to automatically grab all .aspx files and build them as resources. This SO post seems like the solution, but I would prefer not to have to edit the .csproj every single time I add a new view to the project. Is there a way to use a wild cards or some other batch/global conditionally statement to change resources from content to embedded?

    Read the article

  • Which .NET exception to throw for invalid database state?

    - by jslatts
    I am writing some data access code and I want to check for potentially "invalid" data states in the database. For instance, I am returning a widget out of the database and I only expect one. If I get two, I want to throw an exception. Even though referential integrity should prevent this from occurring, I do not want to depend on the DBAs never changing the schema. I would like to use the System.IO.InvalidDataException, except that I am not dealing with a file stream so it would be misleading. I ended up going with a generic applicationexception. Anyone have a better idea?

    Read the article

1