How to add an Entity from a table with different names and with all its relations

Posts   
 
    
Makhaly_cs avatar
Makhaly_cs
User
Posts: 27
Joined: 12-Jan-2009
# Posted on: 23-Sep-2012 23:31:38   

Dear ALL;

I have a table names Message that have an ntext field. I want to create two Entities in my LLBL GenPro 3.5 Version that one entity will contain all fields and the other entity will exclude the ntext field.

I have added with a nother name but it does not take the relation.

Please advise...

daelmo avatar
daelmo
Support Team
Posts: 8245
Joined: 28-Nov-2005
# Posted on: 24-Sep-2012 02:54:05   

Hi Muhammad,

LLBLGen Pro Designer won't load a new set of relationships for entity copies. Here is the reason, quoted from this thread:

Otis wrote:

when you create a copy of an entity with e.g. less fields, you get a new set of relationships with the entities the original also has relationships with, but the related entities do too, namely with the copy , and that's the problem. This leads to odd situations where the related entity now actually should get two FK fields (or two entities controlling the same FK field if you will, even if you don't actually use FK fields, they're technically there, also inside NHibernate. So the fk field is shared among relationships, which is supported btw, but not recommended) which are actually the same: one for the real entity and one for the copy. This could lead to weird situations where you set fkSideEntity.PkSide1 to an instance of PkSide, but after that you do fkSideEntity.PkSide2 to an instance and what should happen then? unclear.

Hence there are no relationships created for copies during reverse engineering (as you don't control the reverse engineering of relationships in that process). You could say: "but if the relationship is with a copy, it should be allowed!", true, but what if the copy is a copy of a copy? ... things get hairy pretty quickly in that respect.

You could add model-only relationships to the copy though. BTW, if you are doing this because you want to exclude a big field from the fetches, and you are using LLBLGen Runtime Framework, the you can exclude it. See Including/Excluding fields for fetches.

David Elizondo | LLBLGen Support Team
Makhaly_cs avatar
Makhaly_cs
User
Posts: 27
Joined: 12-Jan-2009
# Posted on: 24-Sep-2012 08:33:39   

Thanks alot for your reply but how i can exclude this field in LLBLGenPro DataSource Control?

Shall i create the entity collection and fetch the desired fields and then assign it to the datasource EntityCollection Property?

Walaa avatar
Walaa
Support Team
Posts: 14995
Joined: 21-Aug-2005
# Posted on: 25-Sep-2012 00:24:34   

I assume you are using the LLBLGenProDataSource in a web application. Then you will need to set LivePersistence to false, and handle different events as shown here.

Then on the PerformSelect handler you would use the ExcludeIncludeFieldsList as follows:

protected void MyGrid_PerformSelect(object sender, PerformSelectEventArgs2 e)
{
     using(DataAccessAdapter adapter = new DataAccessAdapter())
     {
         adapter.FetchEntityCollection(e.ContainedCollection, e.Filter, e.MaxNumberOfItemsToReturn, 
         e.Sorter, e.PrefetchPath, myExcludedFieldList, e.PageNumber, e.PageSize,);
     }
}