The output for generated files

Jun 19, 2010 at 9:08 AM

Hi,

Very smart. I like your stuff and consider to use your templates in my new projects.

It is a good practice always to separate Data Access layer and business logic layer (Entity data model and CSLA business classes in this case) in two different project. My question is: is it possible to output generated files in other directory then default?

Some naming conventions requests. IMHO, it would be better to take naming conventions from CSLA space, not from Entity framework.       
Instead of
      public class Key : CriteriaBase<Key>
      private void Child_Delete(Key key)
it would be better
      public class Criteria : CriteriaBase<Criteria>
      private void Child_Delete(Criteria criteria)

Maybe it would be better in synchronous factory methods instead of
      internal static Customer New()
      internal static Customer Get(CslaExtensionDemo.Library.Data.Customer data)
call it:
    internal static Customer NewCustomer()
    internal static Customer GetCustomer(CslaExtensionDemo.Library.Data.Customer data)

Keep it going, guys and thank you.

Igor

Coordinator
Jun 19, 2010 at 11:43 AM

Hi Igor.

It is possible to generate files in other assembly. In that case you should add an EF model in one assembly (DataAccess), and a T4 template in other (BusinessLogic). Then open the T4 template and edit path to the EF model (relative path: ..\DataAccess\EfModel.edmx). 

About naming conventions:

- Key is a special Criteria class used internally for different scenarios, not just for loading a single object from the database. You can have many Criteria classes for one CSLA class.

- New() and Get() can be named with class name as suffix, but I can't see any reason to do that. For me it's the same thing (Customer.New() or Customer.NewCustomer()). If that's a big issue for you, we can add new generation option.

~Josip

Jun 19, 2010 at 4:30 PM

Thank you, Josip. It works for me.

"Then open the T4 template and edit path to the EF model (relative path: ..\DataAccess\EfModel.edmx). "

 If you'll also solve the issue with multiple generated namespaces (see previous request) it would be then perfect.

"For me it's the same thing (Customer.New() or Customer.NewCustomer()). If that's a big issue for you, we can add new generation option."

You don't need to add this option because of me. May be it only my personal preference. Anyway, i can than customize this template for me like this:

       #region Synchronous Factory Methods
        <#= (entity.IsItemChild) ? "internal" : "public" #> static <#= entity.ItemName #> New<#= entity.ItemName #>()

Igor

 

Jun 26, 2010 at 10:58 AM

It is possible to generate files in other assembly. In that case you should add an EF model in one assembly (DataAccess), and a T4 template in other (BusinessLogic). Then open the T4 template and edit path to the EF model (relative path: ..\DataAccess\EfModel.edmx).

If i make a new project for my Business layer (CslaExtensionDemo.BusinessLayer) i get following namespace for generated data to access my entity:

using (var ctx = Csla.Data.ObjectContextManager<CslaExtensionDemo.BusinessLayer.NorthwindEntities2>.GetManager("NorthwindEntities2")) .

But my entities are in another project (CslaExtensionDemo.Library.Data) and i need follow namespace to reference them:

using (var ctx = Csla.Data.ObjectContextManager<CslaExtensionDemo.Library.Data.NorthwindEntities2>.GetManager("NorthwindEntities2"))

Maybe i did something wrong?

Coordinator
Jun 28, 2010 at 7:07 AM
You have to edit namespaces for the generated code. Click on the edmx designer, open properties and edit "Csla BL Namespace" and "Csla DAL Namespace". ~Josip
Jun 28, 2010 at 1:51 PM
Yes Josip, i've tried it already before. If i put any walue(for example: CslaExtensionDemo.Library.Data) in CSLA DAL Namespace property, i get always popup window "Properties Window" with the message "Property value is not valid." (Details: "Object reference not set to an instance of an object."). With "Csla BL Namespace" everything is OK.
Coordinator
Jun 28, 2010 at 2:19 PM
Edited Jun 28, 2010 at 2:20 PM
Hm, sounds like a bug to me. I'll create new work item and try to fix it as soon as possible.
Coordinator
Jun 28, 2010 at 2:22 PM
This discussion has been copied to a work item. Click here to go to the work item and continue the discussion.
Coordinator
Jun 29, 2010 at 7:09 AM
Edited Jun 29, 2010 at 7:10 AM
I could not reproduce this bug. I've created a new solution with 3 projects: BLL, DAL and UI. I've added EF model to the DLL project, T4 template to BLL, and changed namespaces. Only thing that I've noticed is that code is not generated when EF model is changed. I had to execute T4 template manually (right click template -> run custom tool).