SilverFox55
asked on
Update Database from RIA Services / Entity Framework without User interface objects.
I'm working on a project that requires Siverlight and RIA Services.
I am able to retrieve a set of records through RIA services. I can load them into a data grid, edit them and stuff them back into the database. Easy enough.
However, I need to accomplish this behind the scenes without loading the data into a UI component.
I need to cycle through the records in the data set, set some flags based on values in another table and save them.
I can get it done by using a hidden datagrid and incrementing the SelectedIndex value, but that seems like a hack.
What is the correct way to do this. I'm sure it's simple, but I can't find an example.
Thanks in advance!
I am able to retrieve a set of records through RIA services. I can load them into a data grid, edit them and stuff them back into the database. Easy enough.
However, I need to accomplish this behind the scenes without loading the data into a UI component.
I need to cycle through the records in the data set, set some flags based on values in another table and save them.
I can get it done by using a hidden datagrid and incrementing the SelectedIndex value, but that seems like a hack.
What is the correct way to do this. I'm sure it's simple, but I can't find an example.
Thanks in advance!
ASKER
Yeah - I've been playing around with intellisense and can't find anything that exposes the fields in the entities. If I bind them to a UI elements, no problem. Change the value and SubmitChanges(), and I'm done. I'm just not finding a way to walk through the collection and change the flags. For instance, I created and loaded a DataContext:
-------------------------- ---------- ---------- ---------- ---------- ---------- ---------- ---------- ---
productDomainContext _productDomainContext = new productDomainContext();
_productDomainContext.Load (_productD omainConte xt.GetNewP roductsQue ry());
-------------------------- ---------- ---------- ---------- ---------- ---------- ---------- ---------- ---
Works great. If I bind this to a datagrid, I see the expected records. Now, what I want to do is take a batch number, combine that with a colorcode from the products table and a sequence number to create a serial number for the product. No user interface is required for the process. That's where I get stuck. The code should be something like this:
-------------------------- ---------- ---------- ---------- ---------- ---------- ---------- ---------- --
string batchID = "ABC123";
int batchSeq = 1;
foreach (product in _productDomainContext)
{
product.serialNumber = String.Concat( batchID,"-", product.colorCode, "-", batchSeq);
batchSeq++;
}
-------------------------- ---------- ---------- ---------- ---------- ---------- ---------- ---------- ---
Of course, if this worked, I wouldn't be asking this question.
When I attempt to compile, I get the error:
-------------------------- ---------- ---------- ---------- ---------- ---------- ---------- ---------- --
" foreach statement cannot operate on variables of type 'namespace.productDomainCo ntext' because namespace.productDomainCon text' does not contain a public definition for 'GetEnumerator' "
-------------------------- ---------- ---------- ---------- ---------- ---------- ---------- ---------- --
I think I can make this work if I can get past this point, but I'm not finding a solution.
--------------------------
productDomainContext _productDomainContext = new productDomainContext();
_productDomainContext.Load
--------------------------
Works great. If I bind this to a datagrid, I see the expected records. Now, what I want to do is take a batch number, combine that with a colorcode from the products table and a sequence number to create a serial number for the product. No user interface is required for the process. That's where I get stuck. The code should be something like this:
--------------------------
string batchID = "ABC123";
int batchSeq = 1;
foreach (product in _productDomainContext)
{
product.serialNumber = String.Concat( batchID,"-", product.colorCode, "-", batchSeq);
batchSeq++;
}
--------------------------
Of course, if this worked, I wouldn't be asking this question.
When I attempt to compile, I get the error:
--------------------------
" foreach statement cannot operate on variables of type 'namespace.productDomainCo
--------------------------
I think I can make this work if I can get past this point, but I'm not finding a solution.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
I've requested that this question be deleted for the following reason:
No comment has been added to this question in more than 21 days, so it is now classified as abandoned and is now flagged for deletion.
If there is a valid solution, please OBJECT and indicate the comments that are, or would otherwise lead to, a solution.
Use the specific format https:#axxxxxxxx for comment ID(s).
Also, please don't object simply because the author did not respond to your comment. While we understand this is frustrating, unfortunately we cannot force the author to return to the question. Unless you feel you have presented a valid, verifiable solution we'll simply delete the question.
Experts-Exchange Auto Deleter
No comment has been added to this question in more than 21 days, so it is now classified as abandoned and is now flagged for deletion.
If there is a valid solution, please OBJECT and indicate the comments that are, or would otherwise lead to, a solution.
Use the specific format https:#axxxxxxxx for comment ID(s).
Also, please don't object simply because the author did not respond to your comment. While we understand this is frustrating, unfortunately we cannot force the author to return to the question. Unless you feel you have presented a valid, verifiable solution we'll simply delete the question.
Experts-Exchange Auto Deleter
I believe this has been answered with a solution that can be implemented and tested.
https://www.experts-exchange.com/questions/27145171/Update-Database-from-RIA-Services-Entity-Framework-without-User-interface-objects.html?anchorAnswerId=36095168#a36095168
https://www.experts-exchange.com/questions/27145171/Update-Database-from-RIA-Services-Entity-Framework-without-User-interface-objects.html?anchorAnswerId=36095168#a36095168
I probably would not be able to write a good sample in C# as I usually code in VB, but hopefully it is simple enough. If you are using a DomainDataSource control in xaml, check the DataContext property to see what type of object it is creating for it. That is the one you will want to create and load queries with in code.
I was able to discover the rest using intellisense alone. Just call YourDataContextObject.Load
Best of luck.