This thread looks to be a little on the old side and therefore may no longer be relevant. Please see if there is a newer thread on the subject and ensure you're using the most recent build of any software if your question regards a particular product.
This thread has been locked and is no longer accepting new posts, if you have a question regarding this topic please email us at support@mindscape.co.nz
|
I understand LightSpeed might have some issues working with objects that have composite keys. When one of the fields in the composite keys are also a foreign key it further complicates things.. And I think that's exactly what I'm having trouble with here. The two classes work OKAY on their own, but I'm not being able to associate them (one:to:many). I've read through some posts and tried Ivan's recommendations but so far no luck. Can some one please help? Here are the tables and columns I'm trying to match on. RECIPES.RECIPE_CODE = RECIPE_LINES.RECIPE_CODE Here are my classes:
[Table("RECIPES", IdColumnName = "RECIPE_CODE")] public class Formula : Entity<string> { private string _Description; public string Description { get { return _Description; } set { Set(ref _Description, value); } } [ReverseAssociation("RecipeCode")] public readonly EntityCollection<Formulation> _Formulations = new EntityCollection<Formulation>(); public EntityCollection<Formulation> Formulations { get { return Get(_Formulations); } } }
[Table("RECIPE_LINES")] public class Formulation : Entity<RecipeLinesID> { private string _DESCRIPTION; private string _input_Unit; public string Description { get { return _DESCRIPTION; } set { Set(ref _DESCRIPTION, value); } } public string InputUnit { get { return _input_Unit; } set { Set(ref _input_Unit, value); } } [ForeignKeyField("Id.RecipeCode")] public EntityHolder<Formula> _RecipeCode = new EntityHolder<Formula>(); }
public struct RecipeLinesID { private readonly string _RECIPE_CODE; private readonly string _PART_CODE; private readonly int _INPUT_QTY; private readonly int _SYS_VERSION_NUMBER; private readonly int _RECIPE_LINE_TYPE; private readonly int _RECIPE_LINE_NUMBER; public RecipeLinesID(string RecipeCode, string PartCode, int InputQTy, int SysVersionNumber, int RecipeLineType, int RecipeLineNumber) { _RECIPE_CODE = RecipeCode; _PART_CODE = PartCode; _INPUT_QTY = InputQTy; _SYS_VERSION_NUMBER = SysVersionNumber; _RECIPE_LINE_TYPE = RecipeLineType; _RECIPE_LINE_NUMBER = RecipeLineNumber; } public string RecipeCode { get { return _RECIPE_CODE; } } public string PartCode { get { return _PART_CODE; } } public int InputQTy { get { return _INPUT_QTY; } } public int SysVersionNumber { get { return _SYS_VERSION_NUMBER; } } public int RecipeLineType { get { return _RECIPE_LINE_TYPE; } } public int RecipeLineNumber { get { return _RECIPE_LINE_NUMBER; } } }
|
|
|
I think the issue is that ForeignKeyFieldAttribute needs to refer to the field name rather than the property name. Normally this isn't an issue but in your case they differ by an underscore. (LightSpeed automagically handles leading underscores but not interior underscores.) Try: [ForeignKeyField("Id.RECIPE_CODE")] Or change the _RECIPE_CODE field name to _recipeCode and use ColumnAttribute to map it to the RECIPE_CODE column -- this may be a better bet anyway because the LightSpeed query engine requires field names so keeping field names in sync with property names is usually a wise move if you want to be able to query on them. |
|
|
Thanks Ivan for the quick response. That fixed it! |
|