Avonelle's Tech Blog

Go Back

And one more BLD / LLBLGen / View Item…

Just discovered one other item I want to remember when using views with LLBLGen and BLD: If the underlying table has a primary key defined as an Identity(), you will want to add some field mapping information in your view. Specifically you’ll want to go into the Field mappings section in the LLBLGen designer and change the “Sequence” for your primary key to @@IDENTITY.

Most things will work without this, but one thing that won’t is passing the newly generated primary key value for your entity to another form or using it in some other way.

Posted by Avonelle on Monday, April 08, 2013. There are 0 Comments.

Additional items when creating views for using with BLD

Follow-up to this post on creating views that are used with LLBLGen and BLD:

  • If the view contains a field that should be optional (in other words – allows NULL values), you may need to explicitly mark it as optional in LLBLGen. At least I had to in the case of a column that was a foreign key reference. (So perhaps that is also relevant.) Otherwise an error was generated if the user tried to save the record but didn’t select a value for that field.
  • Make sure any dependencies you add reference fields that exist. I tend to put the dependency attributes on the table entity, but if you do that and reference a field that is only in the view it will be ignored (no error).

Posted by Avonelle on Monday, January 28, 2013. There are 0 Comments.

BLD Server-side Validation Difficulties

Sometimes with BLD it will appear that a server-side validation rule isn’t working. Actually the record isn’t getting inserted/updated, but the validation error doesn’t appear. For the types of pages I build, this usually means that the user is returned to a list page, but it can also manifest itself in other ways. This is very confusing.

The actual cause is that I’m using the BLDFormView_ItemInserted or BLDFormView_ItemUpdated events to identify what the system should do after the data is inserted or updated. And this code will be executed even if the record isn’t really inserted or updated. Like I said: confusing.

The solution is that within that event, you can test for an exception. Here’s some example code:

Private Sub fvQuestion_ItemInserted(sender As Object, e As FormViewInsertedEventArgs) Handles fvQuestion.ItemInserted
    'Need to check for survey side exceptions, or it will automatically execute even though no record was inserted
    If e.Exception Is Nothing Then
      'What should happen if successful…
    End If
  End Sub

So this event should always be checking for exceptions if you are using it.

Other potential causes of validation problems are Ajax (so try turning it off) and validation groups.

Posted by Avonelle on Saturday, January 26, 2013. There are 0 Comments.

When creating views for using with BLD

Sometimes it makes sense for me to create a view to use with BLD instead of the table directly. This is usually because I also want to include a calculated field that is best calculated in the database. For example: a “CanBeDeleted” bit value for records that don’t have any associated children records.

I typically create a view, then use LLBLGen to generate an entity from that new view. There are some things I need to remember when using this with BLD (but most of these are really LLBLGen tasks):

  • Mark a primary key for the view in LLBLGen, or records won’t be editable (and in fact the “Edit” button won’t appear in your UI).
  • Identify any relationships to other tables within the view in LLBLGen. Otherwise foreign keys won’t work.
  • I prefer to create entities for the table entity also and I put most or all of my annotation attributes there. Then I use <AttributeSource> on the view metadata to copy the attributes from the entity to the view metadata.
  • <AttributeSource> copies Data attributes (business rules) but not structural attributes, like AssociationDbInfo (used for foreign keys).

Posted by Avonelle on Friday, January 18, 2013. There are 1 Comments.

When BLD DataAnnotation attributes aren’t working…

This is a reminder of things that I should double check when one of my BLD DataAnnotation attributes doesn’t appear to be working. Almost always it is something I’m doing wrong, so here are some things to check. Many of these items relate generally to .NET and how partial classes work, but is important with BLD because they don’t throw errors, just result in things not working.

  • Is the property name in the metadata the same as my LLBLGen class? Remember: with partial classes these must be exact, and it is case sensitive (even in VB.NET).
  • This also applies if it is reference to another table. For example: QuestionEntity references the SectionEntity, and it is named Section in the LLBLGen class, so it must be the same name in the metadata.
  • The BLD business rules classes and the LLBLGen classes have to go into the same project for partial classes to work.
  • Metadata classes execute no code except attributes. So calculated properties have to go into entity tables, not EntityMetadata classes.

Also a useful thing to checkout is the DescriptorsBrowser.aspx page, which will show the attributes that are being added to your entities. I’ve been able to figure out what was going wrong by checking there.

Posted by Avonelle on Friday, January 18, 2013. There are 0 Comments.

Separating Out Your Business Logic using ASP.NET Web Forms

These days almost all of the development work I do is with ASP.NET Web Forms. I’m a big fan of Web Forms – it is a technology that has helped me productively build applications for my customers for the last 10 years. However, one negative thing about Web Forms is that many of your business rules are embedded in the page markup as validation controls. Yuck.

Fortunately Peter Blum has developed a technology that solves this problem. He calls it Peter’s Business Logic Drive UI (BLD), and I’m currently using it on my latest project. BLD lets you define your business rules in separate classes, which are then used by the presentation layer to create a UI that includes the appropriate user interface, complete with validation controls that match the business rule logic.

Frankly my description of the product doesn’t do it justice, so if you are interested in this, you should definitely read more about it at Peter’s site, PeterBlum.com. But I do want to add a few remarks about it.

First, Peter’s documentation and support are second to none. You might expect that since his business is just him, the support would suck, but in fact, Peter provides terrific email support and has for years. And his documentation is outstanding. BLD’s PDF documentation is currently over 2,000 pages. Wow.

Second, if you decide to give BLD a spin, expect that it will take you some time to learn. I was already familiar with Peter’s validation controls, but that really didn’t prepare me for how different developing using this approach is. But once you get the basics under your belt, you won’t want to go back.

Third, you might find that using a code generation tool like CodeSmith or T4 to get your business rule classes started will help a lot. In my case, I use CodeSmith to generate my initial BLD classes from my database tables. My CodeSmith templates use some simple logic for adding business logic attributes. For example:

  • Date fields add the attribute for date types so the UI shows a date picker
  • if the column name includes “email” it adds an attribute so that email validation rules are included
  • If the column name includes “phone” it adds an attribute so that phone formatting and validation rules are included
  • etc.

Other than Peter’s website and documentation, there isn’t a lot of information about BLD online. Since Google/Bing tend to be the first place I look when I’m stuck, this is limiting my options. So I’ll be adding stuff I learn about BLD here, so at least they’ll be captured by the magic of the internet, even if only for me.

Posted by Avonelle on Thursday, January 17, 2013. There are 0 Comments.