problem with 1:1 relation

Posts   
 
    
nevernet
User
Posts: 67
Joined: 01-Feb-2010
# Posted on: 29-Dec-2010 09:56:35   

Hello

table 1: product


ProductId(PK)
Name
Type
Code

table 2: product detail


ProductDetailId(PK)
Detail
ProductId(FK)

now, the the ralation is 1:m between product and product detail, how to change it to 1:1 relation?

and now i want to get content from two table. code as below:


ProductEntity entity = new ProductEntity(productId);


//get details
ProductDetailEntity entityDetail = entity.CsbProductDetail[0];

above code will generate two sqls, how to do it in ONE sql?

any ideas will be appreciated. Thanks in advance.

Walaa avatar
Walaa
Support Team
Posts: 14995
Joined: 21-Aug-2005
# Posted on: 29-Dec-2010 10:20:03   

For 1:1 relation, do the following.

table 2: product detail

ProductId(PK)(FK)
Detail

Then you can use the designer to make this an Inheritance Relation. And so:

ProductDetailEntity entityDetail = new ProductDetailEntity(productId);

Would fetch from both tables.

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39908
Joined: 17-Aug-2003
# Posted on: 29-Dec-2010 10:52:31   

Or define a unique constraint on the ProductId fk field in ProductDetail.

Frans Bouma | Lead developer LLBLGen Pro
nevernet
User
Posts: 67
Joined: 01-Feb-2010
# Posted on: 29-Dec-2010 11:33:00   

Hello

great replies many thanks for both of your help.

morbia
User
Posts: 12
Joined: 28-Apr-2009
# Posted on: 20-Oct-2011 14:07:45   
ProductId(PK)(FK)
Detail

Using above format without implementing inheritance and using Detail as property of Product i am getting below error while saving Detail:

System.ArgumentNullException was caught Message=fieldsPersistenceInfo can't be null. Parameter name: fieldsPersistenceInfo Source=SD.LLBLGen.Pro.ORMSupportClasses.NET20 ParamName=fieldsPersistenceInfo StackTrace: at SD.LLBLGen.Pro.ORMSupportClasses.DynamicQueryEngineBase.CreateInsertDQ(IEntityFieldCore[] fields, IFieldPersistenceInfo[] fieldsPersistenceInfo, IDbConnection connectionToUse) at SD.LLBLGen.Pro.ORMSupportClasses.DataAccessAdapterBase.CreateInsertDQ(IEntity2 entityToSave, IFieldPersistenceInfo[] persistenceInfoObjects) at SD.LLBLGen.Pro.ORMSupportClasses.DataAccessAdapterBase.CreateQueryForEntityToSave(Boolean insertActions, EntityBase2 entityToSave, IPredicateExpression updateRestriction, InheritanceHierarchyType typeOfHierarchy, IFieldPersistenceInfo[] persistenceInfoObjects) at SD.LLBLGen.Pro.ORMSupportClasses.DataAccessAdapterBase.PersistQueue(List`1 queueToPersist, Boolean insertActions, Int32& totalAmountSaved) at SD.LLBLGen.Pro.ORMSupportClasses.DataAccessAdapterBase.SaveEntity(IEntity2 entityToSave, Boolean refetchAfterSave, IPredicateExpression updateRestriction, Boolean recurse) at SD.LLBLGen.Pro.ORMSupportClasses.DataAccessAdapterBase.SaveEntity(IEntity2 entityToSave, Boolean refetchAfterSave, Boolean recurse)

I am using SD.LLBLGen.Pro.DQE.SqlServer.NET20.dll v2.6.08.1114 SD.LLBLGen.Pro.ORMSupportClasses.NET20.dll v2.6.9.327

Is it not supported or is it a bug?

nevernet
User
Posts: 67
Joined: 01-Feb-2010
# Posted on: 20-Oct-2011 16:09:47   

i have not tried it. maybe you should add another Primary Key. simple_smile

daelmo avatar
daelmo
Support Team
Posts: 8245
Joined: 28-Nov-2005
# Posted on: 20-Oct-2011 21:12:20   

morbia wrote:

ProductId(PK)(FK)
Detail

Please post more info about your entities/tables and inheritance.

David Elizondo | LLBLGen Support Team