DataSource Controls :: Update Method Using SQL To Entities
Apr 14, 2010
I'm having a question about an update method using SQL To Entities. I'm sending an object to the class and i'm updating him sucefully, but i need to specify each property of object instead of update in once. For example
[Code]....
In this case, i'm updating name, age and country sucefully but i want to use instead of update each property one-by-one, something like this:
[Code]....
So, the C = New should fill the C with all New values on properties, but this isn't work. To update an object, i've to update each property individual or can i update all in one like C = New?
I have an ObjectDataSource that I want to perform updates using a business entity i.e. Type="Object"). Since the values for the entity are within a user control, I have stored a reference to the control in Session and in the updating event, set the new instance to the value of the entity from the user contol property (which also pulls values from the form viaother properties of the control):
Protected Sub MasterDataSource_Updating(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.ObjectDataSourceMethodEventArgs) Handles MasterDataSource.Updating Dim entity As New Login() Dim accountControl As AccountInfo = TryCast(Session("AccountCtrl"), AccountInfo) entity = accountControl.Entity e.InputParameters.Add("entity", entity) End Sub
My question is, how can I get the update method to pass this entity to the update method in my BLL class? It seems the Update method requires an ID or reference to the original object to use in determining whether any changes have taken place, but I don't really want to do this. In other words, I just want to use the Update event on my ObjectDataSource to pass my entity to the method ("Update") I set as a property and then let this business method handle the update of the data. Shown below, is the BLL update method I want to call:
Public Overloads Function Update(ByVal entity As Login) If entity Is Nothing Then Throw New ArgumentNullException("entity") End If MyBase.Update("UpdateLogin", entity.Username, entity.Password, entity.FirstName, entity.LastName, entity.Role, entity.Region, _ entity.Email, entity.Title, entity.TierID, entity.Street, entity.City, entity.State, entity.Zip, entity.Mobile, entity.Phone, entity.Fax) End Function
When I try to call this as it stands now, I get an error: ObjectDataSource 'MasterDataSource' could not find a non-generic method 'Update' that has parameters: ID, entity. Previously, I'd set up a long list of parameters of basic data types (string, int, boolean), but this is rather cumbersome and I was hoping to use an entity for this (FYI, I also got the same type of error when I tried this approach, but with the ID as the last parameter in the list). Perhaps what I'm doing here is atypical to how the ODS is normally used?? Has anyone done something like this successfully?
Out of this 10 rows 3 Rows have their RowState as Added, 2 rows as Modified, and 4 as Deleted.
Now i want to use Datadapter's InsertCommand, UpdateCommand and DeleteCommand
Is it possible to update datatable's changes to Database with Single DataAdpater.Update(DataTable) Call.
Means i will call DataAdapter.Update(DataTable) method only once and with this all new added rows should be inserted in database, modified rows should be updated and deleted rows should be deleted from Database.
I am creating an Asp.net web site which will support dynamic data. When I am creating a dynamic web site from Scratch (from template in VS) all is working fine. But when I am trying to add dynamic entity (.edmx) file and running the application I am getting following error
"The method 'Skip' is only supported for sorted input in LINQ to Entities. The method 'OrderBy' must be called before the method 'Skip'. "
I'm trying to add new rows to a data table and then use the sqldataadapter update method bu fund some problems. First, I written this code:
[Code]....
Excuse me but the most part of variable are in italian, however I think it is possible to understand how does it work. If I execute this code I obtain this error:
System.InvalidOperationException: Update requires a valid InsertCommand when passed DataRow collection with new rows.
After this I added these lines of code just above the last line:
SqlCommandBuilder cb = new SqlCommandBuilder(adapter); adapter.InsertCommand = cb.GetInsertCommand;
and I obtained this error:
Cannot convert method group 'GetInsertCommand' to non-delegate type 'System.Data.SqlClient.SqlCommand'. Did you intend to invoke the method?
error "ObjectDataSource 'ObjectDataSourceCaseDetails' could not find a non-generic method". I have an update method and my ObjectDataSource is hooked up to the method in my BLL. review my code below
I try to update the detailview control. got this error messsage.
ObjectDataSource 'odsDetail' could not find a non-generic method 'Update' that has parameters: hospitalID, hospitalName, taxID, address1, address2, city, state, zip.
I bind this to a GridView but I'm not looking to edit row by row. Instead my GridView has a bunch of TemplateFields with textboxes. I also have a Button that when pressed, invokes the Update method of the ODS. So then the "UpdateTestData" function in my TestBLL is called. This looks like this:
public void UpdateTestData(MyTestDataTable dt) { QueriesTableAdapter qta = new QueriesTableAdapter(); qta.UpdateTestData(dt); }
At run-time in debug, it seems like the object for the signature above is not populated with the data from my GridView.
I'm creating entity on a project to use them as data on my website. I got my base simple entity Users and my DataContext. The thing is i would like the database to create the table as i create Entities.
I mean, actually my database doesn't have a Users table and do not generate it as i build and launch the project. I used to be a Java dev and in Java the table can be created with JPA so i guess Microsoft made it possible with ASP.net but how to do? I've looked on the web but didn't find it.
I'm trying to update data with the EF I can't seem to get the EntityKey when I debug and hit this line befor I save changes _entities.ApplyPropertyChanges entityToEdit.EntityKey .EntitySetName, blogEntryToEdit); The EntityKey is null dose anyone have any idea how this key is set can't SaveChanges() without it _entities.ApplyPropertyChanges(entityToEdit.EntityKey .EntitySetName, blogEntryToEdit);
I am building a web application in asp.Net 4.0 and entity framework. I am trying to retrieve a list of products based on a collection of id's. I first gather all the id's in a collection and then pass it to the linq query. I am trying to get a functionality similar to the IN clause in SQL. The problem seems to be with the Contains() method in the Linq to entities query. Here is my Linq code:
[Code]....
I got the above Linq to entities method from here: [URL]
I trying to create a search mechanism for records in a EDM based on text entered on a text box in a web page.
For example, if I enter a partial name of a customer and/or state abrebiation for that customer on the Text Box (abc, TX)s, I want to search name and state fields in a Customer table in my database for matching customers.
I found a solution with the namespaceSystem.Linq.Dynamic, but for some reason it is not working. It does not expose the Search() method. Here is the code I am using to perform the search;
I have a Customer object that has two address ID fields (one for HomeAddress and one for WorkAddress)
I am loading the Address Objects by using Include="HomeAddress, WorkAddress" and then binding to the properties using the Navigation Property on the Customer Entity
Can I use just one FormView for doing the Insert/Updates and binding it to an EntityDataSource or would I have to do all the Inserting/Updating manually?
I have a GridView and on a row being deleted I trigger the GridView1_RowDeleting sub, but I receive an error "LINQ to Entities does not recognize the method 'System.Web.UI.WebControls.TableCell get_Item(Int32)' method, and this method cannot be translated into a store expression." Code is:
Private Sub GridView1_RowDeleting(sender As Object, e As System.Web.UI.WebControls.GridViewDeleteEventArgs) Handles GridView1.RowDeleting ' The deletion of the individual row is automatically handled by the GridView. Dim dbDelete As New pbu_housingEntities ' Remove individual from the bed. Dim remove_bed = From p In dbDelete.Beds _ Where p.occupant = GridView1.Rows(e.RowIndex).Cells(3).Text _ Where p.room = GridView1.Rows(e.RowIndex).Cells(6).Text _ Where p.building = GridView1.Rows(e.RowIndex).Cells(5).Text _ Order By p.id Descending _ Select p remove_bed.First.occupant = "" dbDelete.SaveChanges() ' Increase number of open spaces in room. Dim update_occupancy = From p In dbDelete.Rooms _ Where p.room1 = GridView1.Rows(e.RowIndex).Cells(6).Text Where p.building = GridView1.Rows(e.RowIndex).Cells(5).Text _ Select p update_occupancy.First.current_occupancy = update_occupancy.First.current_occupancy - 1 dbDelete.SaveChanges() End Sub
The specific line erroring out is: remove_bed.First.occupant = ""
In Entity framework I have a class which is effectively
fooEntity { public Guid Id {get; set;} and a collection of fooChildEntity } a fooChildEntity is again an entityframework class fooChildEntity { public Guid kidId {get; set;} }
Now I also have a pair of business layer classes foo and fooChild
foo { public Guid Id {get; set;} ilist<fooChild> Children {get;set;} } fooChild { public Guid kidId {get; set;} }
My aim is to write a linq to entites that will allow me to convert the entity foo and children into the business foo and children without breaking deferred execution ( I will be adding filters to reduce the recordset at a higher coding level in the business layer)
doing something like
this.context.fooEntity
.include(fooChildEntity)
.Select( fe => new foo { Id=fe.Id ,
fe.foreach(fec => Children.add( new fooChild { kidId = fec.kidId}))})
.AsIQueryable()
is plainly rubbish and would never compile - it is however an indication of the direction I was thinking .
Even if I got a foreach to work like that or similar it would break deferred execution
At this point there are around 300,000 foo entities which I will eventualy filter to 5 or 6 foo's - this is why deferred execution is needed.
Im my MVC 3.0 Application, I created a helper like below;
[Code]....
And I used that helper in a linq query as below;
[Code]....
When I fire my app, it gives me the below error. LINQ to Entities does not recognize the method 'System.String GenerateURl(System.String)' method, and this method cannot be translated into a store expression. Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
Exception Details: System.NotSupportedException: LINQ to Entities does not recognize the method 'System.String GenerateURl(System.String)' method, and this method cannot be translated into a store expression. Source Error:
Line 43: public Blogs GetBlog(string urlstring) { Line 44: Line 45: return GetAll().SingleOrDefault(x => BlogUrlGeneration.GenerateURl(x.ArticleTitle).Equals(urlstring)); Line 46: } Line 47:
İn my blog, the link will be like below; [URL] so I need to set the above urlgenerator class into lambada. How can I do that? What would it take to make that work perfectly
I am working on my first project with Linq to Sql entities/winforms, and I have little problems updating the entities childs in the main form, when I come back from the entity editor....
I have a list of people, and I can edit them or add new. The edited or new person opens in a new form and can have many addresses that can be added modified from the person editor and it opens a third form...
when I have finished edit the new address, so i return to the person editor and add the address, within the person entity context... so person.address.add(newAddress)...
Then I update the list of addresses, referencing: Datasource= foreach(address adr in person.addresses).And when I have finished editing the person i return to the mainform and save the changes from that entity.
_datacontext.save()
The problems I have are that if there is a new person, and I don't add addresses, the person saves without problem. But It doesn't do it if I add any address. With the updates I haven't any problem, they updates all, adds new addresses, but I can't remove anything with the person.addresses.remove(address)...