I am using EF 4.0 and I have created 3 entities from DB.
In DB, I have the following tables Employee,Contact,Department.
Employee Table -> EmployeeID,Name,Designation
ContactTable -> ContactID,Address,CellNo,EMployeeID(FK)
Department Table -> DepartmentID,Name,EmployeeID(FK)
After converting into entities from DB, I get following entities
EmployeeObject ->
EmployeeID,Name,Designation,Contact(Another Entity),Department(Another Entity).
Till this its ok, now I want to bind the employees to data grid its also work fine...
I use below code to bind employees to record ...
code working perfectly, now issue is when I see the data into grid , Two extra column comes
into grid, Contacts and Departments.
Please see the image
Click here to see screenshot of result grid
Entity Model Pic
I want to bind only records which are into employee table not the object which are in
entity (Contacts and Department.)
Related
I followed this great guide to help me add a search feature to my Access database:
http://www.techrepublic.com/blog/howdoi/how-do-i-populate-an-access-list-control-with-the-results-of-a-dynamic-search/108
At the end it says:
"If you’re building a quote or order, use the list control’s Click or Double Click event to copy record(s) to a temporary table. It’s easy to implement using a fixed query for each search task."
I have managed to display all search results in a list box and I would like to be able to click on a customer to highlight them, and then press a button to add an order to the selected customer. I've been thinking how I could do it and I really can't get my head around it.
Any help would be appreciated.
It depends on how you build your database. My guess is that one easy way would be:
Create a table with customers;
Create an "Order" table with orders where you link the customers through a foreign key
You load the customers in a listbox. While making the name visible, it is actually the ID that you retrieve when clicking the listbox. You can configure this via the wizard in the design view of a table. You can make other forms appear by events on the listbox (eg. on click).
If you managed to retrieve the ID of the customer, and you have the data related to the order (data that can easily be extracted from form objects and loaded into variables ) what you need is an insert statement and insert the values in the "Order" tabel (including the customer ID, which is linked through the foreign key).
This way all order records are linked to the customer and can be queried later.
Due to my limited knowledge on your other requests, I cannot help you any further on the rest of your database design.
I hope that my reply could help you and that I understood your question correctly.
You can access info from a listbox via:
List.Value
Or if it is not the first column then:
List.Column(0,0)
0 being the column and row references.
You may also consider using a listview over a listbox and then you can access the relevant parts of a listview control with the following code:
ListView.SelectedItem
Or if it is not the first column then:
ListView.SelectedItem.SubItems(3)
3 being the column reference
I am creating a web app in MVC 3 using entity framework, and recent spec changes have required I add a new column to one of the database tables (a record creation date).
I have added the new column and populated it with values for my existing records, and updated the model in the entity framework. When I look at the object corresponding to the table with the new column, I can see a property for this new data: however the data for that property is not being retrieved.
Just to clarify:
I added column "CreatedDate" (datetime) to table "Orders" in my database
I populated this column with values for my existing records and set it to "not null"
I updated the model in entity framework
My model "Order" now has a non-nullable property "CreatedDate"
I populate a list of orders using LINQ ("from o in DB.Orders select o")
For any entry on my list, entry.CreatedDate returns "01/01/0001 00:00:00", not the value I have entered into the database.
What's going wrong?
EdmMetadata table?
Do you have an EdmMetadata table in the database? As far as I know, this table contains a key that is signed by the structure of the database. So if this value is not changed, the code could not be seeing the change. Good news is that this table is no longer needed:
modelBuilder.Conventions.Remove<IncludeMetadataConvention>();
I have a relational database lets say it consist of an Employee's Table and Department's table and an EmployeesType Table.
The employee's table has a DepartmentId, EmployeeTypeId foreign Keys
and now I created a silverlight app with an entity data model and generated a domain service class
and now I want to show employees info in a grid .. of course I can't show Department name and EmployeeType Name in the Grid
I have to use the Include Data annotation in my metadata ..
I did this .. but how can I show all the included fields in one query?
I used this
public IQueryable<Employee> GetEmployeesWithDepartments()
{
return this.ObjectContext.Employees.Include("Department.EmployeesType");
}
but I managed to show departments only.. What About the other foreign keys?
How can I add them to my query?
When you bind to Employee - you access Department id something like:
{Binding Employee.Department.Id}
And you access EmployeeType like
{Binding Employee.EmployeesType.Id}
Is that what you asking?
Ok guys .. so after two freaking days of trial and error .. i finally found it
here is what you should do ..
in your getEmployees Method or whatever method of retrival you use you can include all your forign keys as follow
public IQueryable<Employee> GetEmployeesWithDepartments()
{
return this.ObjectContext.Employees.Include("Department").Include("EmployeeType");
}
and so on for every forgin key you have included in your metadata class
then in the front end you can now have access to the Department Property and use the Binding syntax to bind it with your View
as follow:
<TextBlock Text="{Binding Department.DepartmentName"/>
Thanks for trying to help
I created a database that holds a STUDENT table, a COURSE table, and an intersection table named STUDENT_COURSE. However, I have problems with duplicated rows and I don't know how to solve them.
Here are pictures of the tables in design view and many-to-many relationship I have created.
http://imgur.com/P7DI1l&THH7A (Be sure to click the "Second Image" link to view the relationships picture.)
In an attempt to simplify data entry, I used the form wizard to set up a SCHEDULE form (and subform).
http://imgur.com/isf4Y&ARYu3
As you can see, one enters the student data in the form and the course data associated with that specific student in the subform. However, when one enters course subform data, it creates a new courseID (autoNumber). This new courseID results in duplicate courseNames (See "Linear Algebra" entries in above imgur link via "Second Image") so that associated students aren't grouped together when one queries by class.
Is there a flaw in my design? Am I not using the form correctly to enter data? Please help me troubleshoot this.
Thank you very much!
Your subform should be based on STUDENT_COURSE table and not on COURSE one. You can still add columns from COURSE table to the subform to display course related data.
Here are some links:
http://www.techrepublic.com/article/accommodating-a-many-to-many-relationship-in-access/5285168
http://www.dhdurso.org/articles/ms-access-forms-pg4.html
http://en.allexperts.com/q/Using-MS-Access-1440/Help-form.htm
I am working on a Silverlight 4 project. I am using WCF RIA on the server and expose the model using a DomainService. I have 2 tables, let's say Table1 and Table2 linked with Foreign key say FID.
Therefore, i can Load data from both table 1 and table 2 in single data grid.
But my question is while editing datagrid if i need to change foreign key's Link, let's say row 1 is linked to foreign key FID1 and I want to change that link to FID2. In same time i want change the content of table 2 in data grid on that row.
Example
datagrid1[ID1 Name Add FID1 F_post F_Name] => [ID1 Name Add FID2 F_post2 F_Name2]
Thanks
I don't see the problem ...
Have you used the automatically generated data source templates?
That should automatically set the linked object as something like a drop down list.