Fields mapped on related fields

Posts   
 
    
yogiberr
User
Posts: 432
Joined: 29-Jun-2005
# Posted on: 22-Dec-2005 15:40:37   

hiya,

A bit of a basic question here.

I want to populate a winforms 2.0 datagrid with the read + write contents of the Nothwind "products" table.

I want to be able to display the "categoryName", instead of the "categoryId".

So, with the products entity, I have created a "field mapped on a related field". this is mapped onto Categories.CategoryName

I try to change the value using the "unitOfWork", but it doesn't persist...YET, the "isReadOnly" box is NOT checked when I generate the project

[code] products.EntityClasses.ProductsEntity currProduct = new products.EntityClasses.ProductsEntity(1);

currProduct.CategoryName = "Condiments";

UnitOfWork uow = new UnitOfWork(); uow.AddForSave(currProduct); uow.Commit(new Transaction(IsolationLevel.ReadCommitted, "UOW"), true); [\code]

Essentially, I want display a combobox column in the datagrid that can be used to change the particular "category" for a product.

I hope the question made sense.Maybe there is a better approach?

many thanks,

                  yogi   ;) 
Walaa avatar
Walaa
Support Team
Posts: 14950
Joined: 21-Aug-2005
# Posted on: 22-Dec-2005 15:53:36   

Fields mapped on related fields can't be re-assigned directly, you will have to re-set the FK (Product.CategoryID = NewValue)

yogiberr
User
Posts: 432
Joined: 29-Jun-2005
# Posted on: 22-Dec-2005 16:18:46   

Ok Walaa,

I think I understand. I have now:

Added the "categories.categoryName" field to the "products typed list."

Bound this to the datagrid.

The categoryName column appears correctly in the datagrid...good so far

However, I think I am confused about the following: 1) apparently, typed lists are read-only, so how do I bind the datagrid to an updateable datasource?? Do I somehow have to create a "list" of entities?

2) even after i have managed to create a readWrite datasource for the datagrid, I am not sure how I can add the "combobox" column, as I want to:

a) create the combobox column in the "categorName" column of the datagrid. b) ACTUALLY update the "categorId" field of the datasource, as you correctly stated.

Walaa, this is just my example, but if anyone can point me to a ready-made example, I'm sure I can take it from there.

(By the way, why is the formatting not working? I've been trying to re-edit this post for 10 minutes to make it more readable..apologies)

many thanks,

yogi

(Otis) You missed a double quote. The ubb parser then thinks you made an argument mistake and thinks it's all an error.

Walaa avatar
Walaa
Support Team
Posts: 14950
Joined: 21-Aug-2005
# Posted on: 23-Dec-2005 07:40:17   

1) apparently, typed lists are read-only, so how do I bind the datagrid to an updateable datasource?? Do I somehow have to create a "list" of entities?

Use EntityCollection instead.

Check this thread if you are working in a stateless environment http://www.llblgen.com/TinyForum/Messages.aspx?ThreadID=4968

2) even after i have managed to create a readWrite datasource for the datagrid, I am not sure how I can add the "combobox" column, as I want to: a) create the combobox column in the "categorName" column of the datagrid. b) ACTUALLY update the "categorId" field of the datasource, as you correctly stated.

check these links: http://www.llblgen.com/TinyForum/Messages.aspx?ThreadID=1199 http://forums.microsoft.com/MSDN/ShowPost.aspx?PostID=150068&SiteID=1

yogiberr
User
Posts: 432
Joined: 29-Jun-2005
# Posted on: 23-Dec-2005 11:49:51   

thanks Walaa,

I'm not using a stateless app, it's winforms 2.0.

Thanks for the help though, I can work thru many of your suggestions.

cheers,

yogi