Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Setting Defaults
Message
 
À
09/09/2009 09:51:09
Timothy Bryan
Sharpline Consultants
Conroe, Texas, États-Unis
Information générale
Forum:
ASP.NET
Catégorie:
The Mere Mortals .NET Framework
Divers
Thread ID:
01423203
Message ID:
01423266
Vues:
28
A ha Moment! Thanks Tim and Kevin, it's only 9am and I feel so enlightened!

Eric

>Yes, to get a hard coded default values added, you just set a default value on some field. In order to get dynamic defaults and a DefaultValues class you need to set something to be dynamic. For instance if you were to highlight a string column in a table (in the blg) and then click on "Set Default" checkbox but leave the default value textbox empty a DefaultValues class would be created because it figures you need a dynamic default value to be created at runtime. When you want to have a default values class you can just do that to cause it to be created and then just edit this class to include or exclude what you want.
>
>The reason it didn't generate anything started with not having any coded in your table, but also included that you didn't set anything on any columns when you ran the generator. For instance I always click on my primary key and make sure the "Required" is checked and then I check the "Set Default" box as well. I enter Guid.NewGuid() in the textbox so it gets added as a default value - hard coded. I like to add my PK in the application business layer so it is more available to me. It is already required in the data layer however.
>I hope that helps.
>Tim
>
>>Ah, thanks for bringing that up, Tim, because I did not actually get a default values object when I ran through the generator. I even re-ran it to see if I missed something. The particular table has no default values hardcoded into the table's definition, so I assumed that was why it didn't generate anything. Is that why?
>>
>>
>>>Hi Eric,
>>>
>>>I just thought I would add a couple of comments although I am sure you already know these. When you run the business Layer Generator the Defaults object would be created in its own file such as SeminarFeeDefaults.cs. It would look just like your description below however. Then in the other thing is the HookSetDefaultValues override would already be there if you set any hard coded default values such as a PK with Guid.NewGuid(); This method is in the business object rather than the entity objet and would look like this.
>>>
>>>protected override void HookSetDefaultValues(SeminarFeeEntity entity)
>>>{
>>>    if (this.DefaultValues != null)
>>>    {
>>>        // Store the dynamic default values via the entity object
>>>        entity.numEventID = Defaults.iEvSemId;
>>>    }
>>>    // Store the hard-coded default values via the entity object
>>>    entity.myPK = Guid.NewGuid();
>>>}
>>>
>>>
>>>Like I said, I am sure you realize this but putting it down for any other lurkers.
>>>Also, I agree about the Dev Guide and the product for that matter. Once you learn your way around the flexibility is fantastic.
>>>Tim
>>>
>>>>Hey, great it worked!
>>>>
>>>>To recap (for my own benefit as much as anyone else's), in order to add default values to an existing business object who's default values weren't created when you created them with the MM.Net Business Layer Generator:
>>>>
>>>>1. In the Entity.Partial.cs file, create a new default values class, eg.
>>>>
public class SeminarFeeDefaultValues
>>>>    {
>>>>        public int iEvSemId = 0;
>>>>
>>>>        public SeminarFeeDefaultValues(int iEventId)
>>>>        {
>>>>            this.iEvSemId = iEventId;
>>>>        }
>>>>2. In the same file, in the main class definition for the entity, add an override method for HookSetDefaultValues, eg.
>>>>
  protected override void HookSetDefaultValues(SeminarFeeEntity entity)
>>>>        {
>>>>            if (this.DefaultValues != null)
>>>>            {
>>>>                // Store the dynamic default values via the entity object
>>>>                entity.numEventID = Defaults.iEvSemId;
>>>>            }
>>>>        }
>>>>3. Also in the same file, add a Defaults property
>>>>
 /// <summary>
>>>>        /// Default values object
>>>>        /// </summary>
>>>>        public virtual SeminarFeeDefaultValues Defaults
>>>>        {
>>>>            get { return (SeminarFeeDefaultValues)this.DefaultValues; }
>>>>            set { this._defaults = value; }
>>>>        }
>>>>        private SeminarFeeDefaultValues _defaults;
>>>>4. Now when you create a new Entity (or new Row in a dataset where I'm using it), be sure to use the overloaded method and seed the default value
>>>>
 // Add a new row to the DataSet
>>>>        oFee.NewRow(ds, oFee.TableName, new SeminarFeeDefaultValues(iEventId));
>>>>
>>>>
>>>>That does it.
>>>>
>>>>And Kevin, let me add that the MM.Net Developer's Guide is one of the best resources for .NET programming I've encountered. It's really really good.
>>>>
>>>>Thanks!
>>>>
>>>>Eric
>>>>
>>>>
>>>>
>>>>>Eric,
>>>>>
>>>>>>protected override void HookSetDefaultValues(OrderDetailEntity entity)
>>>>>>{
>>>>>> if (this.DefaultValues != null)
>>>>>> {
>>>>>> // Store the dynamic default values via the entity object
>>>>>> entity.OrderID = Defaults.OrderID;
>>>>>> }
>>>>>>}
>>>>>>
>>>>>
>>>>>The Defaults property is generated by the Business Layer Generator -- only if you have dynamic default values (vs,. hard-coded values). It looks like this on the OrderDetail business object:
>>>>>
>>>>>
/// <summary>
>>>>>/// Default values object
>>>>>/// </summary>
>>>>>public virtual OrderDetailDefaults Defaults
>>>>>{
>>>>>	get { return (OrderDetailDefaults)this.DefaultValues; }
>>>>>	set { this._defaults = value; }
>>>>>}
>>>>>private OrderDetailDefaults _defaults;
>>>>>
>>>>>Best Regards,
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform