This project has moved. For the latest updates, please go here.

Parent Child Fetch Help

May 22, 2013 at 8:51 AM
Hello

I have these two tables

USE [Scheduler_CodeGen]
GO

/ Object: Table [dbo].[business] Script Date: 05/22/2013 13:10:38 /
SET ANSI_NULLS ON
GO

SET QUOTED_IDENTIFIER ON
GO

SET ANSI_PADDING ON
GO

CREATE TABLE [dbo].[business](
[business_id] [int] IDENTITY(1,1) NOT NULL,
[name] [varchar](100) NULL,
[4patientcare] [varchar](50) NULL,
[websystems] [varchar](50) NULL,
[demandforce] [varchar](50) NULL,
[twitter_account] [varchar](50) NULL,
[twitter_password] [varchar](50) NULL,
[facebook_account] [varchar](50) NULL,
[facebook_password] [varchar](50) NULL,
[status_color_option] [varchar](50) NULL,
[business_metadata] [varchar](max) NULL,
CONSTRAINT [PT_COMPANY_KEY] PRIMARY KEY CLUSTERED
(
[business_id] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY]

GO

SET ANSI_PADDING OFF
GO



USE [Scheduler_CodeGen]
GO

/ Object: Table [dbo].[employee] Script Date: 05/22/2013 13:11:26 /
SET ANSI_NULLS ON
GO

SET QUOTED_IDENTIFIER ON
GO

SET ANSI_PADDING ON
GO

CREATE TABLE [dbo].[employee](
[business_employee_id] [int] IDENTITY(1,1) NOT NULL,
[business_id] [int] NULL,
[employee_type] [varchar](30) NULL,
[title] [varchar](20) NULL,
[first_name] [varchar](30) NULL,
[lastname] [varchar](30) NULL,
[addressline1] [varchar](30) NULL,
[addressline2] [varchar](30) NULL,
[city] [varchar](50) NULL,
[state] [varchar](20) NULL,
[zip] [varchar](10) NULL,
[workphone] [varchar](20) NULL,
[homephone] [varchar](20) NULL,
[cellphone] [varchar](20) NULL,
[faxnumber] [varchar](20) NULL,
[email] [varchar](50) NULL,
[birthdate] [datetime] NULL,
[ssn] [varchar](1000) NULL,
[sex] [varchar](6) NULL,
[username] [varchar](30) NULL,
[password] [varchar](30) NULL,
[color_code] [int] NULL,
[notes] [varchar](1000) NULL,
[position] [varchar](20) NULL,
[apppointment_book_flag] [varchar](10) NULL,
CONSTRAINT [PT_EMPLOYEE_KEY] PRIMARY KEY CLUSTERED
(
[business_employee_id] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY]

GO

SET ANSI_PADDING OFF
GO

ALTER TABLE [dbo].[employee] WITH CHECK ADD CONSTRAINT [business_employee] FOREIGN KEY([business_id])
REFERENCES [dbo].[business] ([business_id])
GO

ALTER TABLE [dbo].[employee] CHECK CONSTRAINT [business_employee]
GO

Business Is Employee's Parent, I have save the Employee using below Code and It worked Perfectly fine.
    Library.Businesses.BusinessList objBusinessList = Library.Businesses.BusinessList.GetBusinessList();
            Library.Businesses.Business objBusiness = objBusinessList.FindBusinessByParentProperties(Convert.ToInt32(ddlBusiness.SelectedValue));
            Library.Employees.Employee objEmp = objBusiness.EmployeeList.AddNew();

            objEmp.Addressline1 = txtAddressLine1.Text.Trim();
            objEmp.Addressline2 = txtAddressLine2.Text.Trim();
            objEmp.Birthdate = txtBirthDate.Text;
            objEmp.Cellphone = txtCellPhone.Text.Trim();
            objEmp.City = txtCity.Text.Trim();
            objEmp.Email = txtEmail.Text.Trim();
            objEmp.Employee_type = "Admin";
            objEmp.Faxnumber = txtFaxNumber.Text.Trim();
            objEmp.First_name = txtFirstName.Text.Trim();
            objEmp.Homephone = txtHomePhone.Text.Trim();
            objEmp.Lastname = txtLastName.Text.Trim();
            objEmp.Password = txtPassword.Text;
            objEmp.Position = string.Empty;
            objEmp.Sex = ddlSex.SelectedItem.Text;
            objEmp.Ssn = txtSSN.Text.Trim();
            objEmp.State = txtState.Text.Trim();
            objEmp.Title = txtTitle.Text.Trim();
            objEmp.Username = txtUserName.Text.Trim();
            objEmp.Workphone = txtWorkPhone.Text.Trim();
            objEmp.Zip = txtZip.Text.Trim();

            objBusinessList.Save();
From the Above Code you must have got an idea but let me clear the scenrio.

There is Business Class and BusinessList Class also there is Employee and EmployeList Class

From the CSLAGenFork I have Created Editable Root Collection Named from the Business Table and Name it Business and item as BusinessList

Same way I have created Editable Child Collection From Employe table and named it Employee and item as EmployeeList and Choose the Parent Type as Business.

So far I have done anything wrong ? I am using the DTO instead of DataReader

Now I want to Validate the Employee Login Through UserName and Password entered by him How Can I do this... Do I need to add any custom method or some other stuff and if yes then show me how can I do this.

Thanks,
Ronak
Coordinator
May 22, 2013 at 9:03 PM
unique_902 wrote:
Now I want to Validate the Employee Login Through UserName and Password entered by him How Can I do this... Do I need to add any custom method or some other stuff and if yes then show me how can I do this.
Hi Ronak;

Your question is about authentication and CslaGenFork can't help you on that field. You should refer to USING CSLA4 ebook series by Rocky and have a good look at the Project Tracker sample available on CSLA.

Regards,
Tiago Freitas Leal
May 22, 2013 at 9:20 PM
Edited May 22, 2013 at 9:26 PM
You misunderstood my question. It's coincidence that I have used the authentication as an example. I just wanted to know how to fetch the employee data in the above case based on any criteria. Say I want to search the employee based on the First Name and Last Name. How can this be implemented in the Library as well as .aspx.cs.
May 22, 2013 at 10:13 PM
It would be tremendously helpful if you solve my query. I am in dire need to solve this ASAP.

Thanks,
Ronak
May 24, 2013 at 5:20 AM
Hello Tiago,

Please respond to my query.

Thanks,
Ronak
May 25, 2013 at 7:41 PM
Hello Tiago,

I am not sure why you are not responding? If you didn't understand my question then please let me know I will try putting it in different way.

Thanks,
Ronak
Coordinator
May 25, 2013 at 8:22 PM
Edited May 25, 2013 at 8:22 PM
Hi Ronak,

First of all, I think ASAP stuff is completely out of order on an open source project - remember there is no SLA.

Second I'm not sure I did understand your question.

Third from what I understood, I'm not sure this is CslaGenFork related, or even CSLA related.
You ask how to implement something in ASPX, I won't answer that for sure; have a look at the CSLA samples and find your own answer. That's the second time I tell you to look at the samples.
You have a collection and you are asking how do you fetch a member of the collection base on any criteria? You mean you have a collection with all its members loaded in memory and you are asking how to fetch a given one? I can't believe you are asking this!

Now do you have any CslaGenFork related question?
May 25, 2013 at 8:29 PM
Sorry If my ASAP stuff went wrong with you. Let me put up my DAL function over here and ask you about implementing this in the Library.

Sorry once again If my question went wrong with you.
Coordinator
May 25, 2013 at 8:32 PM
Please do not insist with obscure questions or questions unrelated to CslaGenFork. Please do not waste your time posting endless code I won't read.
May 25, 2013 at 8:34 PM
I will not post the endless code.

Please help me out with this as I am totally stuck up in this project implementation.
May 25, 2013 at 8:36 PM
public partial class EmployeeDal : IEmployeeDal
{
public EmployeeDto Fetch(string FirstName, string LastName)
    {
        using (var ctx = DbContextManager<SchedulerEntities>.GetManager())
        {
            var result = (from employeeDto in ctx.DbContext.employees
                          where employeeDto.username == FirstName && employeeDto.password == LastName
                          select new EmployeeDto
                          {
                              Business_id = Convert.ToInt16(employeeDto.business_id),
                              Addressline1 = employeeDto.addressline1,
                              Addressline2 = employeeDto.addressline2,
                              Birthdate = employeeDto.birthdate,
                              Cellphone = employeeDto.cellphone,
                              City = employeeDto.city,
                              Email = employeeDto.email,
                              Employee_type = employeeDto.employee_type,
                              Faxnumber = employeeDto.faxnumber,
                              First_name = employeeDto.first_name,
                              Homephone = employeeDto.homephone,
                              Lastname = employeeDto.lastname,
                              Password = employeeDto.password,
                              Position = employeeDto.position,
                              Sex = employeeDto.sex,
                              Ssn = employeeDto.ssn,
                              State = employeeDto.state,
                              Title = employeeDto.title,
                              Username = employeeDto.username,
                              Workphone = employeeDto.workphone,
                              Zip = employeeDto.zip,
                              Business_employee_id = employeeDto.business_employee_id
                          }).FirstOrDefault();
            if (result == null)
                throw new DataNotFoundException(objectName);
            return result;
        }
    }
}
This is what I have implemented in the DalEF now I want to implement this in the Library and this I want to use it in the UI.

Now My Questions is this if I have 10 business and all business will be having 100s of employees all will be loaded in memory can't I fetch the employe based on this in the UI?
Coordinator
May 25, 2013 at 8:45 PM
Edited May 25, 2013 at 8:45 PM
Quite frankly, you won't go anywhere using this approach.

If you want to use Entity Framework give up CslaGenFork; use one or the other.

Regarding your question, I won't repeat myself. I'm sorry you are stuck. My advice is to search the internet for projects that look like what you are trying to do, BUT PLEASE DO NOT COME BACK WITH THIS ISSUE.