Click here to Skip to main content
15,887,416 members
Home / Discussions / C#
   

C#

 
AnswerRe: LINQ to parse EventLog Query Pin
Ravi Bhavnani3-Feb-10 2:01
professionalRavi Bhavnani3-Feb-10 2:01 
AnswerRe: LINQ to parse EventLog Query Pin
Pete O'Hanlon3-Feb-10 2:14
mvePete O'Hanlon3-Feb-10 2:14 
AnswerRe: LINQ to parse EventLog Query Pin
Palash Biswas3-Feb-10 3:17
Palash Biswas3-Feb-10 3:17 
Questionmulticolumn listview Pin
Member 5903103-Feb-10 0:41
Member 5903103-Feb-10 0:41 
AnswerRe: multicolumn listview Pin
sanforjackass3-Feb-10 0:57
sanforjackass3-Feb-10 0:57 
AnswerRe: multicolumn listview Pin
OriginalGriff3-Feb-10 1:01
mveOriginalGriff3-Feb-10 1:01 
AnswerRe: multicolumn listview Pin
Ramkithepower3-Feb-10 1:22
Ramkithepower3-Feb-10 1:22 
QuestionFluentNHibernate mapping - No Persister for... Please help. Pin
Yoken3-Feb-10 0:04
Yoken3-Feb-10 0:04 
Hi all,

I would greatly appreciate any assistance on this, I have no idea what is wrong Frown | :(
I have a program that runs through excel sheets and populates the following classes:

Product > (contains) > Recipe > (contains multiple) > Material

The population of the objects work 100%, but I keep getting a "No Persister for Product"
error when trying to .SaveOrUpdate(product);


Please go through the code examples and database structure below and let me know what I'm doing wrong. I've been battling for ages and simply can't find the right path. To confirm, I have included the mapping files as an embeded resource (this solved my previous problem).

Much appreciated and thank you in advance!

===================
Database structure:
===================
-Products Table-
Contains various fields, one of which is 'RecipeID' which links to the -Recipes Table-.
One product can have one recipe

-Recipes Table-
Contains ID, PercentageInKg, and MaterialID which links to the -RawMaterials Table-.
The RecipeID is not unique, if a recipe has 5 materials it will have
eg. ID=223 for all 5 entries (as the 5 entries form part of 1 recipe),
MeterialID to each unique material entry, and PercentageInKg for each MaterialID
which is the amount for this specific recipe

-RawMaterials Table-
Contains ID, Name, and CostPerKg.
The MaterialID is unique, listing specific raw materials and its cost per kg.


=================
Class Structures:
=================

public class Product
{
    public virtual int ProductID { get; set; }
    public virtual string Name { get; set; }
    public virtual decimal BatchSize { get; set; }
    public virtual decimal FormulaSG { get; set; }
    public virtual string Appearance { get; set; }
    public virtual string Smell { get; set; }
    public virtual decimal Yield { get; set; }
    public virtual string SolidsPercentage { get; set; }
    public virtual string pH { get; set; }
    public virtual string Viscosity { get; set; }
    public virtual string Colour { get; set; }
    public virtual string FoamDefinition { get; set; }
    public virtual DateTime CreatedDate { get; set; }
    public virtual Recipe Recipe { get; set; }

    #region Overrides
    public override bool Equals(object obj)
    {...}

    public override int GetHashCode()
    {...}
    #endregion
}



public class Recipe
{
    public virtual int RecipeID { get; set; }
    public virtual List<RecipeEntry> RecipeEntries { get; set; }


    #region Overrides
    public override bool Equals(object obj)
    {...}

    public override int GetHashCode()
    {...}
    #endregion
}



public class RecipeEntry
{
    public decimal PercentageInKg { get; set; }
    public Material RawMaterial { get; set; }
}



public class Material
{
    public virtual int MaterialID { get; set; }
    public virtual string Name { get; set; }
    public virtual decimal CostPerKg { get; set; }


    #region Overrides
    public override bool Equals(object obj)
    {...}

    public override int GetHashCode()
    {...}
    #endregion
}


========
Mapping:
========

public class ProductMap : ClassMap<Product>
    {
        public ProductMap()
        {
            Table("Products");
            Id(p => p.ProductID);
            Map(p => p.Name);
            Map(p => p.BatchSize);
            Map(p => p.FormulaSG);
            Map(p => p.Appearance);
            Map(p => p.Smell);
            Map(p => p.Yield);
            Map(p => p.SolidsPercentage);
            Map(p => p.pH);
            Map(p => p.Viscosity);
            Map(p => p.Colour);
            Map(p => p.FoamDefinition);
            Map(p => p.CreatedDate);
            References(p => p.Recipe.RecipeID , "RecipeID");
        }
    }


    public class RecipeMap : ClassMap<Recipe>
    {
        public RecipeMap()
        {
            Table("Recipes");
            Id(p => p.RecipeID);

            Component<RecipeEntry>(x => x.RecipeEntries, m =>
            {
                m.Map(x => x.PercentageInKg);
                m.References(x => x.RawMaterial, "MaterialID");
            });            
        }
    }



    public class MaterialMap : ClassMap<Material>
    {
        public MaterialMap()
        {
            Table("RawMaterials");
            Id(p => p.MaterialID);
            Map(p => p.Name);
            Map(p => p.CostPerKg);
        }
    }



I can populate the objects which shows the correct amount of products, drills down to the recipe and materials for the recipe correctly, but cannot save anything.

I need a way to
1) Save the Product which will in turn save the recipe entries
(and materials, though i can get by doing this seperately)
2) be able to save the materials seperate

Hope you can help! Thanks again,

-Y-
AnswerRe: FluentNHibernate mapping - No Persister for... Please help. Pin
Yoken3-Feb-10 21:07
Yoken3-Feb-10 21:07 
QuestionWork with MS office, PDF, files Pin
Hum Dum2-Feb-10 23:57
Hum Dum2-Feb-10 23:57 
Questionencryption & decryption Pin
3bood.ghzawi2-Feb-10 23:20
3bood.ghzawi2-Feb-10 23:20 
Questionapplication which allow multiple user to work on same file Pin
Sachin Pimpale2-Feb-10 23:03
Sachin Pimpale2-Feb-10 23:03 
AnswerRe: application which allow multiple user to work on same file Pin
Dan Mos2-Feb-10 23:24
Dan Mos2-Feb-10 23:24 
AnswerRe: application which allow multiple user to work on same file Pin
sanforjackass2-Feb-10 23:40
sanforjackass2-Feb-10 23:40 
QuestionInsert New Item to Combobox after Data Binding Pin
pavanig92-Feb-10 22:53
pavanig92-Feb-10 22:53 
AnswerRe: Insert New Item to Combobox after Data Binding Pin
Dan Mos2-Feb-10 23:09
Dan Mos2-Feb-10 23:09 
GeneralI want to write a simple C# compiler Pin
Fired.Fish.Gmail2-Feb-10 21:52
Fired.Fish.Gmail2-Feb-10 21:52 
AnswerRe: I want to write a simple C# compiler Pin
Nuri Ismail2-Feb-10 22:07
Nuri Ismail2-Feb-10 22:07 
GeneralRe: I want to write a simple C# compiler Pin
Fired.Fish.Gmail3-Feb-10 0:50
Fired.Fish.Gmail3-Feb-10 0:50 
GeneralRe: I want to write a simple C# compiler Pin
harold aptroot3-Feb-10 1:43
harold aptroot3-Feb-10 1:43 
GeneralRe: I want to write a simple C# compiler Pin
Fired.Fish.Gmail4-Feb-10 18:11
Fired.Fish.Gmail4-Feb-10 18:11 
GeneralRe: I want to write a simple C# compiler Pin
harold aptroot5-Feb-10 3:28
harold aptroot5-Feb-10 3:28 
Questionc# forms property Pin
ric_c+programer2-Feb-10 20:29
ric_c+programer2-Feb-10 20:29 
AnswerRe: c# forms property Pin
Calla2-Feb-10 21:25
Calla2-Feb-10 21:25 
QuestionGUI automation? Pin
Tridip Bhattacharjee2-Feb-10 19:51
professionalTridip Bhattacharjee2-Feb-10 19:51 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.