LLBLGenDatasource UOW persist updates extra table

Posts   
 
    
G.I.
User
Posts: 172
Joined: 09-Jun-2005
# Posted on: 30-Jul-2007 10:56:17   

Hi,

I retrieve news items for a project by using this code:

ProjectEntity project = new ProjectEntity(projectID);
            EntityCollection<NewsEntity> newsItems = project.NewsItems;

            using (DataAccessAdapter adapter = new DataAccessAdapter())
            {
                adapter.FetchEntityCollection(newsItems, project.GetRelationInfoNewsItems());
            }

            newsItems.Sort((int)NewsFieldIndex.PublishedDate, ListSortDirection.Descending);

            return newsItems;

I bind this collection newsItems to a llblgenDatasource. I update a newsitem in the datasource. When I click on update, it tries to update the project table also. I think it has to do with that I am using the project entity as the start entity, so am I doing this wrong? Should I use a normal predicateexpressions to retrieve the newsitems then? For this code seemed so simple to use simple_smile

I am using the uow for update, this code:

public static void PersistNewsUnitOfWork(UnitOfWork2 uow)
        {
            using (DataAccessAdapter adapter = new DataAccessAdapter())
            {
                uow.Commit(adapter, true);
            }
        }

Best regards,

  • G.I.
Walaa avatar
Walaa
Support Team
Posts: 14946
Joined: 21-Aug-2005
# Posted on: 30-Jul-2007 11:05:35   

I bind this collection newsItems to a llblgenDatasource

How are you doing this? Would you please post code snippet?

G.I.
User
Posts: 172
Joined: 09-Jun-2005
# Posted on: 30-Jul-2007 11:06:43   

Here the code:

 protected void LLBLGenProDataSource2_News_PerformSelect(object sender, PerformSelectEventArgs2 e)
        {
            LLBLGenProDataSource2_News.EntityCollection = newsServices.GetNewsItemsByProjectID(2);
        }

        protected void LLBLGenProDataSource2_News_PerformWork(object sender, PerformWorkEventArgs2 e)
        {
            newsServices.PersistNewsUnitOfWork(e.Uow);
        }
Jessynoo avatar
Jessynoo
Support Team
Posts: 296
Joined: 19-Aug-2004
# Posted on: 30-Jul-2007 23:53:16   

Hi,

Well I'd say if you don't need it, which your code suggests, your NewsItems collection should not be referenced to your projects innercollection.

ProjectEntity project = new ProjectEntity(projectID);
            [b]EntityCollection<NewsEntity> newsItems = new EntityCollection<NewsEntity>;[/b]

            using (DataAccessAdapter adapter = new DataAccessAdapter())
            {
                adapter.FetchEntityCollection(newsItems, project.GetRelationInfoNewsItems());
            }

            newsItems.Sort((int)NewsFieldIndex.PublishedDate, ListSortDirection.Descending);

            return newsItems;

should make it fine. Use inner collections when working with prefetch paths instead, or with explicit updates.

Still, I'd be curious to know what update to project your previous code induce. Could you have a look at the UOW's content?

G.I.
User
Posts: 172
Joined: 09-Jun-2005
# Posted on: 31-Jul-2007 08:17:55   

I have done nothing to update the inner project collection, that's why it's so strange. I retrieve the newsitemCollection and each newsItemEntity has a ProjectEntity as a property with for example, projectID = 2.

Apparantly it thinks it's a new entity, while I have never set isNew to true. So when I try to save my newsitem collection it tries to save all related sub entities also, which is the project entity.

Is there something I am doing wrong here, do I forget something?

Walaa avatar
Walaa
Support Team
Posts: 14946
Joined: 21-Aug-2005
# Posted on: 31-Jul-2007 09:10:27   

Which LLBLGenPro Runtime Library build are you using? (ref: http://www.llblgen.com/TinyForum/Messages.aspx?ThreadID=7720)

Jessynoo avatar
Jessynoo
Support Team
Posts: 296
Joined: 19-Aug-2004
# Posted on: 31-Jul-2007 09:19:46   

Please try my code. The second line fixes your problem (take out the bold tags)

G.I.
User
Posts: 172
Joined: 09-Jun-2005
# Posted on: 01-Aug-2007 07:47:02   

Thank you very much! simple_smile