Entity Framework problem in new Entity Inheritance - asp.net

Could someone with some good knowledge answer this question please. Im having a problem with the schema in my Students.aspx page. I have done the walkthrough, but I get an error and I have copied the edmx file from the sample into my application and I still get the error. This is the error:
'EnrollmentDate' is not a member of
type 'SchoolModel.Person' in the
currently loaded schemas. Near simple
identifier, line 6, column 4.
I have also created a new EntityDataSource and I have the same problem. The sample works fine but I can't seem to get the EnrollmentDate and HireDate fields to be part of the 'SchoolModel.Person' Entity. The part which is Upto setting the EntityTypeFilter then I run the app and I get problems

It sounds like you're following the example on MSDN. By the end of the example, the fields EnrollmentDate and HireDate are no longer on the SchoolModel.Person class, they're on the subclasses SchoolModel.Instructor and SchoolModel.Student.

I faced the same problem while going through that walkthrough. The solution: Just delete the old EntityDataSource control on the page, put new EntityDataSource, configure it as given in walkthrough (with entity set name: People; EntityTypeFilter: Student or instructor), And every thing works as it should!!
Faraz

It sounds like you may have missed one or more EDS controls when you added the EntityTypeFilter attributes. Are you sure all your EDS controls that access students or instructors have EntityTypeFilter="Student" or EntityTypeFilter="Instructor"?

Related

Audit.Net Entity Framework - Independant Associations [Tables Many-To-Many]

Hi i write because i have configured the Audit for one single table for all my entities and its working fine for the general tables in my model, but with the Many-To-Many tables i don't know how can i do for setup the "AssociationEntryRecord"? the event is fired by EF when i do one change in this tables but i don't know how saved!
Could you please help me with this questions, thanks in advance for your help & the library...
For configuring the Entity Framework event provider use the fluent API provided by Audit.EntityFramework.Configuration.Setup()
You can include the associations as follows:
Audit.EntityFramework.Configuration.Setup()
.ForAnyContext(config => config
.IncludeIndependantAssociations());
And about your sample code (what you should have included as textual code and not as an image):
The first line is not needed, since the UseEntityFramework() will
override the DataProvider
The primary key value can be calculated as: entity.TablePk = entry.PrimaryKey.FirstOrDefault().Value.ToString();

MVC nhibernate entiry mapping for dropdown list

I have a dropdown list on an ASP.NET MVC project that I am pretty sure is not binding to my model because of my nhibernate mapping.
I have tried many variations on the asp mvc side resulting in this post here.
MVC side of things seems fine
I believe the issue may be that my object is trying to bind, but my mapping is out of whack.
My mapping is:
<many-to-one name="Project" lazy="false"
class="AgileThought.ERP.Domain.Property.Project"
column="ProjectGUID" />
My View gives an error saying that the GUID from the dropdownList selected value is not valid. Which I think may be that it is trying to push the GUID into my related project object.
The value 'fd38c877-706f-431d-b624-1269184eeeb5' is invalid.
My related project list binds to the dropdown list just fine, it is just not binding to my models Project entity.
Does the related Project entity need to know about its relationship? Its really just a lookup list.
Many thanks for your time and best regards,
Rod
You'd probably need a custom binder that can essentially do this...
entity.Project = session.Load<Project>(selectedValue);
I think Sharp Arch has something like this...check out this + helper method.
If you want to keep it simple, maybe just do it manually.

LINQ to SQL Classes & Datacontext are not created

Afternoon all
This is driving me nuts.
For no apparent reason (of course there must be one), my web project will no longer generate LINQ to SQL classes/data contexts!!!
I am going about the usual routine of right clicking the project, adding new item, selected LINQ to SQL classes, then dragging over a table from Server Explorer, saving and build but no...the bloody thing won't appear!!!
Does anyone know why this might be happening/what have I done wrong?
Figured it out.
Basically, NEVER rename any items.
I had previously been using OnlineReporting in one item, the name space when linq creates the classes was using this as it's namespace.
However, I then later changed this to Reporting but when the linq to sql generation occurred, it was still using the 'old' namespace.
I went into the designer.cs file, amended the name space to match the new format and it worked.

ASP.Net Entity Framework

I'm just trying the ASP.Net Entity framework its the first time I've tried to use an ORM framework so bear with me If I'm barking up the wrong tree.
To simplify the problem I've got the following 2 tables
Calendar
CalendarID
UserID
Date
EventName
Users
UserId
Username
I've added them both to my Entity Framework model and its established the link between the tables. I'm able to then display a list of Calendars from my MVC view, by using something like
<%= calendarEntry.DateAdded%>
However if I then try to use
><%= calendarEntry.Users.Username%> : <%= calendarEntry.DataAdded%>
It falls over on the call to calendarEntry.Users as it says it is null. Why is the entity framework not pulling through the use details? Do I need to change something in my model designer?
If it helps the code in the MVC controller that sends the data to the view is like this
var Entities = new UnityGamersEntities();
return View(Entities.Calendar);
Really hope that makes sense.
for anyone interested I solved this by using the following code
UnityGamersEntities db2 = new UnityGamersEntities();
ObjectQuery<GameCalendar> gc = db2.GameCalendar.Include("GameTitles");
There seems to be a real lack of tutorials for the entity framework, unless you only ever want to work with single tables I found it really hard to find the information I need.
hopefully this will change in coming months.
Gav,
There is another way you can get Linq to Entities to populate the Users Table.
Every Foreign Key and Collection has a "Load" Method on it which will go off to the database and, in your case, fetch the list of users linked to the current calendar and populate the collection. It's kind of like lazy loading.
If you were to add this line it should work:
<!-- Load up Users unless it's already Loaded -->
<% if(!calendarEntry.Users.IsLoaded) calendarEntry.Users.Load(); %>
<!-- Your Line -->
<%= calendarEntry.Users.Username%> : <%= calendarEntry.DataAdded %>
Hope it helps.
PS - I hear you on the lack of documenation
Crafty
You need to tell the entity framework to load the Users for the Calendar.
You can do this VIA the LINQ query, simply:
Calendar cal = (from c in Calendar
where c.CalendarID.Equals(input)
select new
{
c,
c.Users
}).FirstOrDefault().c;
Which says, load the calendar and all its users.
EDIT: There are probably other ways to load the users, this is just the LINQ way.

Asp.net Entity Framework and generated SQL problem

I have a problem with the following Linq query using Entity Framework:
from o in ctx.Entity
where o.EntityID = entityid
select o;
Simple enough right? Well the 'Entity' set is the parent class of a whole lot of other classes. The generated SQL for this simple query is about 20K worth of characters with a slew of 'case' and 'union'. In addition of taking a while for the framework to compile the query, it takes a while to execute too.
So how can I improve the SQL generated by the framework in case of queries using classes with heritage? Or what other technique can I use to avoid this problem?
AD
The reason it is doing that is because of the relationships of Entity with other tables in your database. To cut down on that, you need to read up on how to better control the explicit/lazy loading of references that EF is doing for you
http://blogs.msdn.com/jkowalski/archive/2008/05/12/transparent-lazy-loading-for-entity-framework-part-1.aspx
No post like this would be complete without a plug for nhibernate, which is more powerful/robust/performant/and easier to use ;-) but hopefully that link will help you out

Resources