thanks unfortunately, I can't run anything on it because when I started the formatting I thought I had the serial number, so now the laptop is unusable, but thanks!
thanks unfortunately, I can't run anything on it because when I started the formatting I thought I had the serial number, so now the laptop is unusable, but thanks!
As I thought, Microsoft are completely useless, but they did say though, that since my laptop is samsung, then samsung should hold a list of product keys associated with machines, so perhaps I'll retrieve it that way. I'll get in touch with samsung and see what they say
I could try, but they dropped support of XP ages ago, so I doubt they will help
HI guys, I have to reinstall windows XP onto my samsung nc10 laptop because I want to sell it, but alas, I've just realized that the label at the bottom has faded out completely so I don't have a window key anymore. The thing is the lappy, when I bought it years ago, came shipped with an original copy of windows xp (I have windows 7 at the moment). What should I do to reinstall a genuine copy of windows xp?
thanks
I thought I might start looking at the class as well. This is the way I'm thinking to proceed.
I will have two options - perhaps with radio buttons - to start with:
a)Sale
b)Expense
For a) I will display the name of the item and the price it was sold for. For b) instead I will display the name of the item and the refund/fee paid by me. So I'm thinking that perhaps only one class is necessary:
public class Item
{
public int ItemID { get; set; }
public string Name { get; set; }
public double Price { get; set; }
public double Expense { get; set; }
}
How does it sound to you guys?
HI guys, I'm just about to build a small, simple expenses application. Basically I'd like to keep track of how much money I'll make by selling some stuff, and therefore I have to input the income and have a total of it, the expenses (fee, refunds) and total it and then the effective total (income - expenses), so pretty simple stuff. I'd like to store everything in the database as I'd like to have a record of everything (income per item, total income, total expenses and effective total), but I'm not sure where the calculations should occur (database or on the fly in the application). So for example: say I sell a camera, I'd like to store the price paid and the item on the database. But where do I calculate the total income, expenses and effective total? The thing is so far I've only stored and retrieved stuff from the EF database, not sure what I have to do to make calculations and store the values back in the database.
In terms of data visualization, I'd like to have a good summary of everything, so again I'd like to be able to see what I sold, for how much and keep track of income, expenses and effective total.
Needless to say, if somebody have any suggestions, or think that the way I want to implement the application is wrong, please do let me know. Once we establish the way to proceed I'll think about the classes needed
…
AH OK I seem so essentially this link table keeps track of which patient is associated with which jab. OK got it.
pritaeas, sorry for the slow reply, been away with no access to my laptop.
Thanks for clarifying things and for the link. I had a look and it makes sense to a point, but when I tried to draw it - even taking this http://www.entityframeworktutorial.net/images/entityrelation2.png into consideration I couldn't really assign this link table with the primary keys any functionality, but I guess it's OK, in the sense I still don't fully appreciate it... You did explain it in your post though, so let me try to clear this up, well for me at least. Say PatientA has Jab 1 and 2 and that PatientB has Jab 1,2 and 3: what data ends up in the JabPatient table? Surely the ID of PatientA and PatientB (under the PatientID column) but what under the JabID column?
Going back to my application: I do understand that this link or joining table is important and that it gets the primary keys of both classes, hence the name JabPatient in my case. Going back to what you said at the beginning of the thread, I did notice that, in the courses and students example, class Course doesn't not contain any reference to the studentID: in my case, as you've mentioned, I then don't need the Jab class to have any PatientID because the many to many relationship is created by defining this in the Jab class public virtual ICollection<Patient> Patients { get; set; }
and this one public virtual ICollection<Jab> …
pritaeas, when you said
Isn't it generating a link table
did you mean that my code, well the patientID, was generating a third table? I looked at the table generated and in fact I don't see two tables as I expected to see, but three (the extra one being JabPatient):
So, removing the PatientID will effectively remove the table. Now, could you please explain in layman terms why in a many-to-many relationship the patientID field adds an extra table and it doesn't do that if the relationship is one-to-many?
thanks
Oh I see, I didn't know that, I thought that a foreign key was always invariably needed to link tables, and if we remove it how does a jab object keeps track of which patient it belongs to? I'll remove it from the jab class then and will see what happens :-)
Sorry pritaeas, you lost me. I would have thought PatientID had to be an int because it's a primary key in Patient and a foreign key in Jab, that's why I've declared it an int. A very similar situation occurred in my other thread, the book review app https://www.daniweb.com/web-development/aspnet/threads/497464/much-simpler-first-mvc-application
OK I've done the usual things, as above, but something odd happened: the app displays OK (I haven't done any CSS changes but that will come soon) except for the fact that when I navigate to the Jab page I get something I shouldn't get, a PatientID field, see screenshot here http://s7.postimg.org/8vhezu0sr/jab.png
That PatientID should be a foreign key, so why is it appearing on the page?!
Hi all, I've decided to start another thread for my old health app https://www.daniweb.com/web-development/aspnet/threads/496278/building-first-mvc-application as the old thread was pretty confusing and didn't lead me anywhere. With the knowlegde coming from developing the previous simple book review app here https://www.daniweb.com/web-development/aspnet/threads/497464/much-simpler-first-mvc-application I've also decided to take a different approach: I'll build the app as I go along, meaning, I'll start very simple (two classes minimum) and then I'll continue to update the app and develop the other classes as needed (thanks to @djjeavons now I know I to do successful migrations so databases shouldn't be a problem!).
So, I said I'll start simple. Here is the first two classes of the app, Patient.cs and Jab.cs.
Patient:
public class Patient
{
public int PatientID { get; set; }//primary key
public string Name { get; set; }
public string Surname { get; set; }
public DateTime DOB { get; set; }
public string Sex { get; set; }
public double Height { get; set; }
//public double Weight { get; set; } //this will have its own class
public virtual ICollection<Jab> Jabs { get; set; }
}
Jab:
public class Jab
{
public int JabID { get; set; }//primary key
public int PatientID { get; set; }//foreign key
public string Name { get; set; }
public DateTime Date { get; set; }
public int ShotNumber { get; set; }//which shot is that?
public string Note { get; set; }//in case I need to add some notes …
Hi all, does anybody know of any good guide for beginners to write twitter bots? I had a look around but I couldn't find anything terribly good. Does anybody have any suggestion, something that starts building very simple bots
thanks
Hi guys, I've run into something interesting and I'm a bit stumped with this. Basically I have a form:
<form>
<div class="formWrapper">
<span>Refine your search</span>
<input type="text">
<select>
<option>English</option>
<option>French</option>
<option>Dutch</option>
</select>
<button class="submitButton" type="submit" data-ajaxurl="http://localhost/_myFile.html" data-ajaxtarget="#myFile_search" >Search</button>
</div>
</form>
and some bootstrap pagination links:
<div class="bootstrap_pagination">
<ul>
<li class="active">
<a href="#" data-number = "1" onclick="clicked_bootstrap_pagination(this, event)">1</a>
</li>
<li>
<a href="#" data-number = "2" onclick="clicked_bootstrap_pagination(this, event)">2</a>
</li>
<li>
<a href="#" data-number = "3" onclick="clicked_bootstrap_pagination(this, event)">3</a>
</li>
<li>
<a href="#" data-number = "4" onclick="clicked_bootstrap_pagination(this, event)">4</a>
</li>
<li>
<a href="#" data-number = "5" onclick="clicked_bootstrap_pagination(this, event)">5</a>
</li>
<li class="plain">
<a href="#">›</a>
</li>
<li class="plain">
<a href="#">»</a>
</li>
</ul>
</div>
Somewhere on the page I have a hidden field as well, storing the data-number of the pagination link I clicked on, the default value is 1: <input type="hidden" name="number" value="1">
And this is the function that takes care of the clicked pagination link:
function clicked_bootstrap_pagination(clickedLink, event){
event.preventDefault();
$this = $(clickedLink);
var pageNumberValue = $this.data("number");//get number
var $hiddenField = $("#drivers_initial form input[name='number']");//hidden field
$hiddenField.val(pageNumberValue);//update value of hidden field
$('form .formWrapper button.submitButton').click();//resubmits the form
}
When I click on a pagination link, the function runs it updates the data-number in the hidden input field and resubmit the form, pretty simple.
OK, so here is the problem: when the submit button is clicked on - my search button in the form - I also want to run another function, resetHiddenFieldNumber()
, but the problem is, as you've probably already …
Ah OK, cool, thanks for that DaveAmour
OK, I think I got there in the end. The problem wasn't in fact with any of the views I looked at, but in the index view, specifically here:
<span class="controller">@Html.ActionLink("Edit", "Edit", new { id=item.ReviewID })</span>
<span class="controller">@Html.ActionLink("Details", "Details", new { id=item.BookID })</span>
<span class="controller">@Html.ActionLink("Delete", "Delete", new { id=item.BookID })</span>
No wonder it was broken...I was calling up details and delete with the Book ID and not the review ID. So by changing the above into:
<span class="controller">@Html.ActionLink("Edit", "Edit", new { id=item.ReviewID })</span>
<span class="controller">@Html.ActionLink("Details", "Details", new { id=item.ReviewID })</span>
<span class="controller">@Html.ActionLink("Delete", "Delete", new { id=item.ReviewID })</span>
it works. Thanks for looking at the code anyway:-)!
When you say submit, which one do you mean, edit, delete or view button?
Thanks pritaeas, I've just updated my previous post, and I think I've found the problem, but I have no idea how to resolve it..
About get and post, I haven't touched the details and delete files in that sense, as in whathever method they use it's been put there by the system, so you would think that it is correct?
OK, this I really don't know about. Basically, whenever I add a new review for a book, whenever I try to view the details of that review or delete it (ie click the details or delete button) I get an error, HTTP Error 404.0 - Not Found. The resource you are looking for has been removed, had its name changed, or is temporarily unavailable.
Here is the full screenshot of the error:
http://s2.postimg.org/9yq21kt6x/review.png
But the edit button - calling the edit view - works.
Here are the review details and edit files:
@model BooksApplication.Models.Review
@{
ViewBag.Title = "Details";
}
<h2>Details</h2>
<fieldset>
<legend>Review</legend>
<div class="display-label">
@Html.DisplayNameFor(model => model.ReviewText)
</div>
<div class="display-field">
@Html.DisplayFor(model => model.ReviewText)
</div>
<div class="display-label">
@Html.DisplayNameFor(model => model.Book.BookName)
</div>
<div class="display-field">
@Html.DisplayFor(model => model.Book.BookName)
</div>
</fieldset>
<p>
@Html.ActionLink("Edit", "Edit", new { id=Model.ReviewID }) |
@Html.ActionLink("Back to List", "Index")
</p>
And here the delete:
@model BooksApplication.Models.Review
@{
ViewBag.Title = "Delete";
}
<h2>Delete</h2>
<h3>Are you sure you want to delete this?</h3>
<fieldset>
<legend>Review</legend>
<div class="display-label">
@Html.DisplayNameFor(model => model.ReviewText)
</div>
<div class="display-field">
@Html.DisplayFor(model => model.ReviewText)
</div>
<div class="display-label">
@Html.DisplayNameFor(model => model.Book.BookName)
</div>
<div class="display-field">
@Html.DisplayFor(model => model.Book.BookName)
</div>
</fieldset>
@using (Html.BeginForm()) {
<p>
<input type="submit" value="Delete" /> |
@Html.ActionLink("Back to List", "Index")
</p>
}
Any idea/suggestion?
ADDED: if you need further details, here is what happens. Let's look at the database tables:
Books table
Review table
So, the IDs don't correspond, …
OK, I think I feel a bit like an idiot for finding my own answers only after I post the problem. Of course I don't need to iterate through the objects to check if the model is empty! D'oh!
So, here is the revised, working code.
@if (!Model.Any()) {
<span>Empty!</span>
}
else{
foreach (var item in Model) {
<span class="header"> @Html.DisplayNameFor(model => model.BookName)</span>
<span>@Html.DisplayFor(modelItem => item.BookName)</span>
<span class="header">@Html.DisplayNameFor(model => model.ISBN)</span>
<span>@Html.DisplayFor(modelItem => item.ISBN)</span>
<span class="header">What do you want to do with this book?</span>
<span class="controller">@Html.ActionLink("Edit", "Edit", new { id=item.BookID })</span>
<span class="controller">@Html.ActionLink("Details", "Details", new { id=item.BookID })</span>
<span class="controller">@Html.ActionLink("Delete", "Delete", new { id=item.BookID })</span>
<div class="separator"></div>
}
}
I knew I wasn't too far off!
OK here is another things I'd like to do and it is proving rather difficult. I've made some changes to the CSS just to embellish the app a little and now I was thinking that the first time you land onto the Book/Index or Review/Index and there are no Books/Reviews, I'd like to have a span saying that there are no reviews. Seemed pretty easy, but, it turns out it wasn't. So, let's take myBook/Index view first. I have a foreach loop that adds the details:
@foreach (var item in Model) {
<span class="header">@Html.DisplayNameFor(model => model.ReviewText)</span>
<span>@Html.DisplayFor(modelItem => item.ReviewText)</span>
<span class="header"> @Html.DisplayNameFor(model => model.Book.BookName)</span>
<span class="book">@Html.DisplayFor(modelItem => item.Book.BookName)</span>
<span class="header">What do you want to do with this review?</span>
<span class="controller">@Html.ActionLink("Edit", "Edit", new { id=item.ReviewID })</span>
<span class="controller">@Html.ActionLink("Details", "Details", new { id=item.BookID })</span>
<span class="controller">@Html.ActionLink("Delete", "Delete", new { id=item.BookID })</span>
<div class="separator"></div>
}
So, I need to check if there are any books, so I thought that a
@if (Model.Book.Count ) {
}
would do, but it's complaining saying that
System.COllections.Generic.IEnumerable<BooksApplication.Models.Book doesn't contain a definition for 'Book' and no extension method 'Book' accepting a first argument of type System.COllections.Generic.IEnumerable<BooksApplication.Models could be found (are you missing a using directive or an assembly reference?)
very similar to the message I got previously when I was trying to display a review under the Book details view, and that makes sense as I wasn't iterating through them as I should have. So, I changed the above to sit inside another foreach loop:
…thanks DaveAmour, I thought @URL.Action was merely to get URLs, like if I have something like <div>@Url.Action("Return")</div> inside a Book view it will return /Book/Return.
I had a bried look at the T4MVC as well, but I thought that you can specify when you create a controller whether you want a strong view or not
thanks
Ah! Hold on, I cracked it, looks like I was using the parameters in the wrong order..eh eh. Here is the winning combination:<div class="link">@Html.ActionLink("Go to Reviews", "Index", "Review")</div>
So, link text, Action, Controller!! Darn!
Hello all, I decided to open a new thread which I could use to ask questions about how to customize this new MVC application I created https://www.daniweb.com/web-development/aspnet/threads/497464/much-simpler-first-mvc-application, add HTML and change the default look and feel. If the mods are OK with that, I was thinking to use this thread as a general one and pop in any questions related to that when I get stuck, rather than create a new thread every time about the same app. I hope it is OK.
In fact here is the first question.
I'm trying to customize the Book Index view and add a link from there to the Review Index view, saying something like "Go to reviews". I had a good look online, my understanding is that rather than using hardcoded HTML, it is better to use HTML helpers, and so I did and created this <div class="link">@Html.ActionLink("Go to Reviews", "Review")</div>
I read that this helpers can take several parameters, but I thought I'd do with two, the link text and the controller name. Unfortunately when I try that - remember that I'm in the Book view - the URL becomes localhost/xxxx/Book/Review rather than the localhost/xxxx/Review I was expecting, so it's appending the review controller at the end of the URL the link sits in. Had look online of course, some people say that the routing needs amending and remove the controller part, but isn't that a bit excessive? Then, in the list of possible parameters, I …
Perfect, that's it! Thank you very much for clarifying that!
Thanks djjeavons.
Yes I had a look at the tables as you suggested, table data and table definition.
The view model is interesting actually, but what I meant - and sorry for not being able to articulate that correctly, but I kind of have a lot of gaps that need to be filled evidently :-), is something slightly different. You said:
the Book Details view takes data from both the Book model and the Reviews model as you have the Reviews property. Likewise, the Review Details view is the same due to the Book property.
How does that exactly happen? So, let's take my Book Details view again, which if I'm not mistaken, is a strongly typed view, due to this @model BooksApplication.Models.Book
: which one is the reviews property you're referring to, where is it, other than the one declared in the classes?
Hi djjeavons, yes that's exactly what I meant: I added you code and it works OK. Let me see if I get things right. You said that the Book model has a collection of review properties, is that because the relationship between the Book and the Review is 1 to many? If I look at the Review details view instead, I can see these two lines:
<div class="display-label">
@Html.DisplayNameFor(model => model.Book.BookName)
</div>
<div class="display-field">
@Html.DisplayFor(model => model.Book.BookName)
</div>
So it's essentially doing what I was trying to do with the Book view, but I presume this is allowed here because the Review view has a Book property which isn't a collection, and that's because the review/s can only refer to one book?
Also, can I ask you, are different views somehow connected, in the sense we're accessing one view from the other, why are we allowed to do that? Happy to do some readings, but I've never come across this "link" between them
thanks
Hi, since I've spectacularly failed to build a simple MVC application (for now at least ) https://www.daniweb.com/web-development/aspnet/threads/496278/building-first-mvc-application, I've decided to do even a simpler one, modelled on this one http://www.codeproject.com/Articles/683942/An-Absolute-Beginners-Tutorial-for-understanding-E , which is supposed to create a few books and their associated reviews
I don't think it gets simpler than that. Naturally I run into some issues, but this time it seems to have to do only with the views. Let's look at the code.
So, I created my classes, as always in two separate files:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
namespace BooksApplication.Models
{
public class Book
{
public int BookID { get; set; }
public string BookName { get; set; }
public string ISBN { get; set; }
public virtual ICollection<Review> Reviews { get; set; } //1 book can have multiple reviews, 1 to many?
}
}
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace BooksApplication.Models
{
public class Review
{
public int ReviewID { get; set; }
public string ReviewText { get; set; }
public int BookID { get; set; }//foreign key
public virtual Book Book { get; set; } // This apparently keeps track of the book this review belong to as ever
}
}
The I created the usual things, 2 controllers (BookController.cs
and ReviewController.cs
) with read and write action using EF respectively associated with Book (BooksApplication.Models)
and Review (BooksApplication.Models)
model classes and both with the same data context class BooksApplicationContext (BooksApplication.Models)
, here it is:
Talked to a few people and they're saying that all that notation should be scrapped. Here's an idea, I'll do a simpler example and when I get that to work, I'll come back to this and perhaps re-write it as it seems we're not getting anywhere with this application
tobyITguy, any idea? I mean I'm happy to redo the whole thing from scratch as long as I get clear directions.
OK tobyITguy, I tried the above, but now I get another error when I attempt to create a controller for another class, as it seems it doesn't like that syntax:
[Key, ForeignKey("Patient")]
public int PatientAllergyID { get; set; }
"Unable to receive metadata for MyMedicalRecord_2.Models.Patient. The foreign key component PatiendAllergyID is not a declared property on type Patient. Verify it has not been explicitly excluded from the model and that it is a valid primitive property".
Besides, what does this line mean:
[Key, ForeignKey("Patient")]
public int PatientAllergyID { get; set; }
That PatientAllergyID is primary and foreign key at the same time?!
thanks
This is the allergy class tobyITguy:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;
namespace MyMedicalRecord_2.Models
{
public class PatientAllergy
{
[Key]
public int PatientAllergyID { get; set; }
[ForeignKey("PatientID")]
public int PatientID { get; set; }
public string AllergyType { get; set; }
public virtual ICollection<Patient> Patient { get; set; }
}
}
The rest is on the pastebin link which works now.
Sorry about the dot, copy and paste error, thanks for amending
There is a problem with the classes I think http://pastebin.com/Ei6biJss When I created the controller like so:
and I got this error: "Unable to retrieve metadata for MyMedicalRecord_2.Models.Patient." The navigation property 'PatientID' is not a declared property on type 'PatientAllergy'. Verify that is hasn't been explicitly excluded from the model and that it is a valid navigation property"
This error doesn't make that much sense to me, especially when the PatientID property is declared in the PatientAllergy class. ANy idea?
thanks for clarifying that, I have amended my patient class now, so that it has all primary keys of all the other clases listed, as below:
public class Patient
{
[Key]//primary key
public int PatientID { get; set; }
public int Height { get; set; }
public int Age { get; set; }
public string Name { get; set; }
public int PatientWeightID { get; set; }
public int PatientJabID { get; set; }
public int PatientExercisesID { get; set; }
public int PatientBloodTestID { get; set; }
public int OperationID { get; set; }
public int PatientAllergyID { get; set; }
public int PatientHealthConditionID { get; set; }
public virtual ICollection<PatientAllergy>PatientAllergies { get; set; }
public virtual PatientWeight Weight { get; set; }
public virtual ICollection<Operation> Operation{ get; set; }
public virtual ICollection<HealthCondition>ConditionName { get; set; }
public virtual ICollection<PatientBloodTest> test { get; set; }
public virtual ICollection<PatientExercises> exercise { get; set; }
public virtual ICollection<PatientJab> jab { get; set; }
}
so by adding those primary keys back into the patient class, what happens at tables level? All the other tables are linked back to the Patient table? I'll create the controller (I'm planning to create one controller only that will hopefully allow me to enter all the data and test it) and then I'll post back the results, fingers crossed there won't be any problems
thanks
all right, I've done some work on these darn classes as I need to progress with this.
Based on what tobyITguy and some readings I've done, I have revised the classes, hopefully we're getting closer, even if there are still things that are not clear to me. Here they are:http://pastebin.com/iLdHPQ6X
So, questions now:
1)lets's have a look at some of the classes. Take the Patient.cs:
public virtual ICollection<PatientAllergy>PatientAllergies { get; set; }
public virtual PatientWeight Weight { get; set; }
public virtual ICollection<Operation> Operation{ get; set; }
public virtual ICollection<HealthCondition>ConditionName { get; set; }
public virtual ICollection<PatientBloodTest> test { get; set; }
public virtual ICollection<PatientExercises> exercise { get; set; }
public virtual ICollection<PatientJab> jab { get; set; }
I've used ICollection because the relationship between the patient class and the others is either a 1-to-many or a many-to-many, and the ICollection maintains the many XXX (for example, jabs, operations etc) associated with the patient class. The PatientWeight is different bwcause the relationship is 1-2-many and so, no ICollection. Loosely correct?
2)each other class has a key token with an ID to signify primary key and a foreign key token which is PatientID, for example, take the PatientExercises:
[key]
public int PatientExercisesID { get; set; }
[ForeignKey("PatientID")]
public int PatientID { get; set; }
3)Every class - except Patient of course - also has a reference to the Patient class, depending on the kind of releationship it has with it: if it is …
Hi thanks for your help and the file. I had a good look at it, but to be honest I'm really confused now, and the classes are significantly different from mine, which you know, it's absolutely fine if mine are wrong, but there are things that I don't seem to understand.
Here are the points that are not making that much sense to me, sorry.
1)you said I should use the [key,ForeignKey("Patient")]
, but in your classes, this is never used anywhere, you only have [Key]
in the PatientWeight
and Patient
classes;
2)I used generic collections in my classes, but you've removed them all. Take the Patient class:public virtual List<PatientAllergy> PatientAllergies { get; set; }
and all the other collections: I used them because one patient can have multiple Allergies, Operations etc, is that wrong? Still in the Patient class, PatientWeight
seems to be a collection (you have it down aspublic ICollection<PatientWeight> PatientWeight { get; set; })
? Why is that? There's only one weight per patient. Also is a ICollection<>
different from a List<>
?
3) all the ids on the Patient class:
public int PatientID { get; set; }
public int AllergyID { get; set; }
public int OperationID { get; set; }
public int HealthConditionID { get; set; }
public int PatientBloodTestID { get; set; }
Why storing them in the Patient class and then again in each single class? We essentially have them twice?
4)In each class you have a public virtual …
OK cool, so the foreign key token [key,ForeignKey("Patient")]
needs to be added to every class related to the patient class, correct?
Thanks tobyITguy, yes it makes sense, I should've thought about the name :-). I've got to admit that I'm not entirely clear with all this relationship business - will probably start a thread on that very soon - anyway, I thought that the point of adding public virtual Patient patient { get; set; }
to the other classes was to establish a relations among them (like a patient has one weight, multiple allergies etc) and I would've thought that EF had sufficient information to determine what was the primary key and foreign key, evidently I was wrong. So I don't need to remove the virtual class from the PatientWeight - the error isn't complaining that there is a virtual class - but just add the foreign key: now I suppose that the foreign key token (is that called a token) needs to be added to all the other classes as well so that EF can create the relevant relationships in the relational tables
OK, so I created another application with the new updated classes, it builds OK, but (eh eh yes there is a BUT of course!) there is a problem. It looks like it's not happy about the relationship between the main Patient class and the PatientWeight class: here are both of them:
public class Patient
{
public int Id { get; set; }
public int Height { get; set; }
public int Age { get; set; }
virtual public List<PatientAllergy> PatientAllergies { get; set; }
virtual public List<PatientOperation> Operation { get; set; }
virtual public List<PatientHealthCondition> ConditionName { get; set; }
virtual public PatientWeight weight { get; set; }
virtual public List<PatientJab> jab { get; set; }
virtual public List<PatientBloodTest> test { get; set; }
virtual public List<PatientExercises> exercise { get; set; }
}
public class PatientWeight
{
public int Id { get; set; }
public DateTime DateChecked { get; set; }
public double Weight { get; set; }
public virtual Patient patient { get; set; }
}
"Unable to retrieve metadata for MyMedicalRecord_2.Models.Patient.
Unable to determine the principal end of an association between the types MyMedicalRecord_2.Models>patientWeight and MyMedicalRecord_2.Models.Patient. The principal end of this association must be explicitly configured using either the relationship fluent API of data annotations"
I did a bit of googling, and it looks liks it has to do with the type of relationship involved between the two classes. Is it fair to say that the relationship between patient and …
OK fair enough, thanks for shedding some more light on the tagging and removing the tag. I must admit I didn't know I could remove it myself, but I would have created the thread anyway :-)
Cheers
I think it would be useful if whoever adds tags can also give a reason for that, sorry to labour the point, but this tag on that post just seems really random
Hi Dani, fair enough, but aren't those tags somehow moderated? I mean, that particular post really doesn't seem to me to be the let-me-google-that-for-you kind. I admit though, that sometimes in old posts I have made the mistake of not googling well enough and a tag like that would be more than deserved, but in this case, I've done my research and didn't come up with anything helpful, and this makes me wonder how these tags are awarded to posts
thanks @pritaeas, I actually came across that link myself, but I'm not terribly sure I understood the whole ting about "virtual", in fact I think I'll take the opportunity to clarify it in this post
@tobyITguy, thanks for your reply. I revised the classes I had before and made some changes, like adding the Operation and HealthCondition classes as you suggeste:d here are the latest changes http://pastebin.com/EcKXWqSK
Now, moving on to the virtual business, let's see if I get this right. If I understand it correctly all non-primitive properties need to be virtual to achieve this "lazy loading" thingy, so, my patient class becomes:
public class Patient
{
public int Id { get; set; }
public int Height { get; set; }
public int Age { get; set; }
virtual public List<PatientAllergy> PatientAllergies { get; set; }
virtual public List<Operation> Operation { get; set; }
virtual public List<HealthCondition> ConditionName { get; set; }
virtual public PatientWeight weight { get; set; }
virtual public List<PatientJab> jab { get; set; }
virtual public List<PatientBloodTest> test { get; set; }
virtual public List<PatientExercises> exercise { get; set; }
}
I hope I haven't gone too crazy with the virtual keyboards.
The same way, all my other classes, since they are related to the patient one will get this line public virtual Patient patient {get; set;}
, so, for example, let's take the PatientAllergy, it now becomes:
public class PatientAllergy
{
public int Id { get; set; }
public …
Sorry I posted too many things as I was trying to figure out what was going on, I'll try to explain it more clearly :-).
Basically, I've got all the classes done, they can be seen here http://pastebin.com/AhYbhvkB and then I created my controller as we discussed in one of my latest posts, one controller only so I can test the application and verify that I can add and return data (with read/write action and views using EF). As model class I chose my Patient.css as I cosdider it the "main" class and I created a new data context: then I run the application and a few interesting things happened:
1)if I navigate to the controller URL (http://localhost:62324/Patient/Create) I get this
As you can see there is a lot missing: I only the primitive-type properties are displayed, the non-primitive ones (Operations, Weight etc) are not there instead
and I would have expected to see them there as well, as I would expect to be able to enter weight, blood test, exercises etc...
SO I checked the database, and specifically the Patient table and if you look at the screenshot here you'll notice that the patient table has only Age, Weight and Weight_ID (whatever this is) and all the other properties from the class are just missing. What I don't understand is why. I would expect the table to contain all the …
HI all, I was wondering if anybody could let me know why my post https://www.daniweb.com/web-development/aspnet/threads/496278/building-first-mvc-application all of a sudden has been tagged as "let-me-google-that-for-you" .
Thanks
Oh no sorry, they are not even in the database...
Actually, having done a bit more digging, I discovered something interesting. The fields displayed are only built-in types, like ints and the missing ones are custom types (I think that's the correct way to identify them), like List<PatientAllergy>, List<string>, PatientWeight
. If you look at the below screenshot, you'll see that the custom types are indeed in the database table as you would expect them to be, but, they're just not showing up on the page. Not sure this is a coincidence, is there a special using statement i need to use or something?
Right, so I created this PatientController, er, but there seems to be something strange happening.
Basically when I created iton the add controller window, I selected the Patient.cs class from the drop down Model Class. Now, the controller has been created successfully as well as the various tables in the database, here is the screenshot:
And that's always good news. But I then built the application and run it navigating to the Controller URL, and all I get on the page is weight and age:
I would have thought I would get all the fields instead, so I checked the automatically generated Create view and strangely enough, there are only weight and age in there. Here is the code generated:
@model MyMedicalRecord_1.Models.Patient
@{
ViewBag.Title = "Create";
}
<h2>Create</h2>
@using (Html.BeginForm()) {
@Html.AntiForgeryToken()
@Html.ValidationSummary(true)
<fieldset>
<legend>Patient</legend>
<div class="editor-label">
@Html.LabelFor(model => model.Height)
</div>
<div class="editor-field">
@Html.EditorFor(model => model.Height)
@Html.ValidationMessageFor(model => model.Height)
</div>
<div class="editor-label">
@Html.LabelFor(model => model.Age)
</div>
<div class="editor-field">
@Html.EditorFor(model => model.Age)
@Html.ValidationMessageFor(model => model.Age)
</div>
<p>
<input type="submit" value="Create" />
</p>
</fieldset>
}
<div>
@Html.ActionLink("Back to List", "Index")
</div>
@section Scripts {
@Scripts.Render("~/bundles/jqueryval")
}
Now, I don't believe this is what I'm supposed to see as I should be able to have all the fields available in there, I think?