I am using Devexpress in VS2013. i want to know how can I use my entity framework classes as data source in Devexpress reports(XtraReport). e.g I have a DBset "Employs" in my my DBcontext how can i use it in Xtrareport Data source,
Thanks.
You can easily bind the report to the EF query result if you convert your query to the List and then bind your report to this List:
report.DataSource = (from employee in DbContext.Employees
select employee).ToList();
I believe the following KB article will be helpful:
How to create a master-detail report bound to an ORM (Entity Framework) model in MVC applications
Related
I have tblDepartment and tblEmployee in Database. Added entity data model for data and changing Entities "tblDepartment" to "Department" and
"tblEmployee" to "Employee" .
While Creating Employeecontroller with read/write/edit template using entityframework and scaffolding template then Model Entity "Employee"
not found in dropdown instead it shows "tblEmployee" in dropdown.
Please help.
Thanks,
Dnyaneshwar
Build / Rebuild the solution or your project. Your updates will not automatically reflect esp on controllers.
I am fairly new to working with ASP controls. I am having some issues with a project. This project is fairly large and my team has placed the ADO.NET emtity inside the same solution but placed into a different project inside Visual Studio 2010. The original db was built through SQL Server 2008. I was wondering if it would be possible to connect a GridView control to this entity in order to show certain aspects of it?
Also, If not possible, we have a class Customer which has certain members (name, dob, ssn,...etc) and functions that will pull these customers from the db through the ADO.NET. Could I populate the GridView with a a list of instances of this class?
something like
List<Customers> CustList = new List<Customers>();
....populate the list.....
Gridview.DataSource = CustList;
Gridbiew.DataBind();
Sure you can! Just add a reference the other project from the one that has the GridView, and set the DataSource property of the GridView to the entity that is in the other project. Indeed, this is a common design in applications, to separate them by "layers"(also criticised a lot).
Hope it helps,
I want to create a relationship between a custom table (Websites) and the default aspnet tables related to Users.
I'm using code-first so for most FK relationships I would just do
public ModelName ModelName { get; set; }
With this, EF will automatically create the FK relationships. Very easy.
What's confusing is the most effective way to hook into the aspnet users/membership table. Do I create a new model Users that acts as an interface so that I can implement custom user code?
Is there a best way to do this that fits well into EF best practices? I basically just want to relate a user to the Websites table/model so that EF can do its thing.
"Do I create a new model Users that acts as an interface so that I can implement custom user code?"
If you want flexibility, I would say this is the way to go. This way it would be easier if you wanted to change to some sort of different Authentication DB structure in the future.
For example, have an "AppUser" Entity where the corresponding table has a foreign key to the "UserID" column of the aspnet_Membership table. This way you can simply add properties to your "AppUser" Entity instead of trying to change the MS table structure (which can be a real pain). You can still interact with the built-in MS Membership classes and functions from your MVC project using something like the MvcMembership starter Kit DLL's.
https://github.com/TroyGoode/MembershipStarterKit
Hope this helps!
This has few preconditions:
ASP.NET tables must be in the same database as your own tables
Previous precondition means that you must either create your database and tables manually (without automatic code-first generation) or you must use some custom initializer which will add non mapped ASP.NET tables as part of database recreation
If you want your model class to have relation with ASP.NET table you must model ASP.NET table as another entity. I'm not sure if you can use ASP.NET classes for that because for example MembershipUser doesn't have parameterless public constructor which is required for EF. So you will most probably need to create duplicate classes and their mappings and use these classes when referencing ASP.NET entities.
I am trying to jump from ASP Classic to asp.net. I have followed tutorials to get Entity Framework and LINQ to connect to my test database, but I am having difficulties figuring out ExecuteQuery(). I believe the problem is that I need an "entity class" for my database, but I can't figure out how to do it. Here is my simple code:
Dim db as New TestModel.TestEntity
Dim results AS IEnumerable(OF ???) = db.ExecuteQuery(Of ???)("Select * from Table1")
From the microsoft example site, they use an entity class called Customers, but I don't understand what that means.
Entity Framework comes with a visual designer. In that designer, you connect to your existing database, and you select all the tables (and possibly views) from your database that you want to work with.
From that selection, EF will generate entity classes one for each of your tables, e.g. if you have a Customers table, you'll get a Customer class, if you have a Products table, you get a Product class.
Those classes represent (by default) your table structure 1:1 - e.g. each column in your table gets translated into a property on the class.
Once you have that, you're no longer dealing with SQL statements and stuff like ExecuteQuery() - you leave that to EF to handle for you.
You just ask for what you need, e.g. all your customers from a given state:
var ohioCustomers = from c in dbContext.Customers
where c.State = "OH"
select c;
This statement will return an IEnumerable<Customer> - a list of customers that matches your search criteria.
Is it possible to use a SQL query that returns XML, in order to bind a TreeView control to SQL data? In other words, I would like to set up a query that presents table data as hieracrhical XML, and bind this XML to the TreeView.
Are you assuming to bind TreeView to XmlDataSource (XmlHierarchicalDataSourceView)?
You can implement your own IHierarchicalDataSource and HierarchicalDataSourceView for that. I thinks this solution would be better than returning XML from DB.