How T Save() will work ?

How T Save() will work ?

Old forum URL: forums.lhotka.net/forums/t/12339.aspx


jhoncsla posted on Thursday, January 30, 2014

Normal 0 false false false EN-US X-NONE X-NONE

I am trying to learn CSLA framework, I'm not able to save  some table data. Please let me guide about step-by-step on how to create CSLA ASP.NET website.

I am trying to build a simple CSLA ASP.NET website with simple save , update and delete .

I am having book also of Rockford Lhotka . I would start with a simple template and expand it.

How can I save with given example : If Iam having Employee table with Employee class

Employee newEmployee = Employee.NewEmployee();

Then set the properties and call the save method....

newEmployee.FirstName = " jhon";

newEmployee.Save();

 

I found  public T Save();this  in BusinessBase<T> from metadata

How it will work ? Any Sample application or reference site that  you can provide ?

 

Thanks & Regards:

Jhon

Chris62 replied on Thursday, January 30, 2014

I created a simple example below.

 

    // You'll need to add a reference to the CSLA dll in your project(if you haven't done that already)

    [Serializable]

   public partial class Employee : Business<Employee>

   {

    // This property would normally map to your P/K in the database

    private static readonly PropertyInfo<Int32> EmployeeIDProperty = RegisterProperty<Int32>(p => p.ContactId, String.Empty);

    public Int32 EmployeeId

    {

            get { return GetProperty(EmployeeIDProperty); }

            internal set { SetProperty(EmployeeIDProperty, value); }

    }

    private static readonly PropertyInfo<String> FirstNameProperty = RegisterProperty<String>(p => p.FirstName, String.Empty, String.Empty);

    public String FirstName

    {

            get { return GetProperty(FirstNameProperty); }

            protected set { SetProperty(FirstNameProperty, value); }

    }

   // Dataportal region

    [RunLocal]

    protected override void DataPortal_Create()

    {  }

    private void DataPortal_Fetch(int EmployeeID)

    {

         // You would put your data access here to retrieve the appropriate record from the db

         // CSLA works with different DA technologies, ORM, Inline SQL(w/parameters), Data Readers/Sets etc...

   }

   protected override void DataPortal_Insert()

   {

     // You would put your data here to insert a new row/record into the database here

    // Again, you can use a variety of data access technologies

  }

  protected override void DataPortal_Update()

  {

    // You would put your data here to update an existing row/record in the database here

    // Again, you can use a variety of data access technologies

  }

    }

I forget what chapter in the CSLA book the Dataportal is covered, but that's where you can start.  If you have a good understanding of inheritance/polymorphism you can infer what's going on when you go through the WCF Dataportal when you save.

 

jhoncsla replied on Tuesday, February 11, 2014

Thanks Chris!

JonnyBee replied on Thursday, January 30, 2014

Just want to add that there is several sample applications that you can look at, too. 

My preferred way is to fork the CSLA project on GitHub or use the CSLA installer at http://www.cslanet.com/Download.html 

jhoncsla replied on Tuesday, February 11, 2014

Thanks JonnyBee... installer  is a good example ....

Copyright (c) Marimer LLC