Tracking Forums, Newsgroups, Maling Lists
Home Submit Tracker Forums
  Advanced Search
  HOME    TRACKER    ASP.NET


Advertisements:










MVC :: Creating Foreign Key In Model Classes?


I am trying to create a relation between 2 of my model classes. I have separated my Model classes to be in their own project "Domain Model" and the application exists in the "WebUI" project.

I have 2 models.... SupportIssues and Users....

SupportIssues has a column UserID which is also a primary key in the Users table.

I want to create a relationship where one user can have many support issues.

I just can figure out how to do this?

Here is a snippet of my supportIssue.cs class:

[Code]....

How can i link UserID to my User.cs class?

Is it anything to do with the [Associate] tag?


View 2 Replies (Posted: May 31, 2010 12:28 PM)

Sponsored Links:

Related Forum Messages For ASP.NET category:
Visual Studio :: Configure SQL Server In VS2010 / Creating Model Classes With Linq To SQL?
I can't believe I'm having so much trouble finding this information. I'mendeavouring to learn aboutcreating model classes with Linq to SQL. By default VS2010 wants to use SQL Express, but our organisation has several database servers for development so I'd rather use one of those. PLEASE can somebody tell me how I can configure VS2010 to do that, as all I get is 'A network-related or instance-specific error occurred while establishing a connection to SQL Server ... Verify that the instance name is correct'. Yeah, thanks Microsoft. Actually telling me how to verify the instance name would be a really good move here.

Posted: Mar 17, 2011 10:54 AM

View 1 Replies!   View Related
Map Model Classes To ViewModel Classes Or Aggregate Model Classes In ViewModel Classes
I'm curious as to what people consider better practice, between duplicating model structure in the view model and using a mapping tool to move data between the two, or aggregate the model inside the view model, i.e. have a property on the view model class that is a reference to the actual model. Which is considered a better approach in general?

Posted: Dec 15 10 at 16:31

View 1 Replies!   View Related
MVC :: Foreign Key Relationship Doesn't Create Parent / Child Classes In Datacontext
I have two tables 'Transfore_Reqs' and 'Transfer_Item' with foreign key from 'Transfer_Item' to 'Transfore_Reqs'. When I dragged these two tables to database model design view and I did see the relationship of this foreign key. However, there is no properites created that can refenence to parent and child classes.

Posted: Jul 13, 2009 08:43 PM

View 1 Replies!   View Related
MVC :: How To Use DropDownListFor With Model Binding For Foreign Key Column
I have an edit MVC view page that is built up with the following

<%= Html.DropDownList("PatientID", (SelectList)ViewData["Patients"]) %>

I want to use Html.DropDownListFor, but it doesn't work because it builds up the select list with the name "Patient_PatientID" or "Patient.PatientID" and that then fails in the update.

The controller sets up the following

ViewData["Patients"] = new SelectList(scheduleRepository.FindAllPatients(), "PatientID", "Lastname", appointment.Patient.PatientID);

I can save with this code

Appointment appointment = scheduleRepository.GetAppointment(id);
appointment.PatientReference.EntityKey = new EntityKey("SimpleScheduleEntities.Patients", "PatientID", Int32.Parse(collection["PatientID"]));
scheduleRepository.Save();

Posted: Dec 18, 2009 12:23 AM

View 2 Replies!   View Related
MVC :: Create View With A Model Class With A Lookup / Foreign Key?
I am following along with the Contact example [URL], and using my own model. Instead ofthe Contact class, mine has a foreign key field to a lookup table for "Locations." I havethe following code.

[Code]....

When I fill out my Create view, and submit it I get the following error:

There is no ViewData item with the key 'LocationID' of type 'IEnumerable<SelectListItem>'.

[Code]....

I am guessing I need to add a Location parameter to my Post-Create action, so I can assign it to pagerToCreate.Location. but, how do i pass that in from the view, and is there a more auto-magic way?

Posted: May 14, 2009 08:23 PM

View 2 Replies!   View Related
MVC :: Display Foreign Key-bound Property From Model View
but I am new with MVC and database-driven applications.

I hava a table with Cities (ID,Name) and one with Businesses(ID,CityID,Name). The later has a foreign key relationship with the first table.

I used a linq-to-SQL class to create my models.

My problem is that I need to access the City Name(not the ID) when displaying the Business Model View.

How can I do this? if from my controller I call the View passing the auto-generated Business Model, I only have access to the ID.

Posted: Apr 17, 2010 08:38 PM

View 2 Replies!   View Related
DataSource Controls :: Primary Key - Foreign Key Join In Ado.net Entity Data Model?
I am using Entity Data Model in my web application in VS2008 sp1 and SQl 2008 db

I have two tables

[code]....

Relationship Exists between this Two tables like ErrorType and ErrorType_ID

i have Create entites and all .

Using Sql i am able to Join this tables

Select E. [Error_Code], E.[Error_Type] , ET.[ErrorType_Name] ,E.[ErrorDetails]

From [ErrorCodeDetails] E JoinErrorTypeDetails ET ON E.Error_Type=ET.ErrorType_ID

but using ado.net Entity data model how to do it.

Posted: Dec 23, 2009 10:21 AM

View 5 Replies!   View Related
MVC :: Inherited Model Classes?
This is my first post in this forum and I want to congratulate all the ASP.Net MVC team for this great framework.Somedays ago, I saw the new ASP.Net MVC 2 Model Validation, following the instructions from Scott Gu blog...I found something interesting that I don't know if it's an expected behavior or a bug.My Model class is inherited, so I have something like this:

[Code]....

I have an descendent of this class with some more properties, and the validators for ASP.Net MVC:

[Code]....

Then I found that the Client validation don't work for the inherited property

Posted: Feb 26, 2010 06:10 PM

View 11 Replies!   View Related
SQL Server :: Creating Foreign Key And Primary Key?
Iam new to sql. I got this task to design a table in sql. It has for columns user_ID(PK, FK1) , WebSite_ID (PK, FK2), Create_Dt, Update_Dt How do I create PK and Fk1 and PK FK2 in sql server 2008 R2

Posted: Dec 07, 2010 03:53 PM

View 3 Replies!   View Related
Automatically Generate Buddy Classes From Model In C#
I use Linq to Sql (although this is equally applicable in Entity Framework) for my models, and I'm finding myself creating buddy classes for my models all the time. I find this time consuming and repetitive. Is there an easy way to automatically generate these buddy classes based on the models? Perhaps a visual studio macro?

[MetadataType(typeof(PersonMetadata))]
public partial class Person
{
}
public class PersonMetadata
{
public object Id { get; set; }

Posted: Apr 28 10 at 19:10

View 4 Replies!   View Related
MVC :: How To Use Of Validation With Data Annotations In Model Classes
I make use ofvalidation with data annotations in my model classes. How do I make sure this annotations are not violated when I validate data in my business layer, before sending it to the DAL? I guess I don't want to define the validation rules in two places (model classes and in my BLL-classes)?

Posted: Dec 12, 2010 07:36 PM

View 6 Replies!   View Related
MVC :: Change The Default Template For Model Classes?
I tried ASP.NET MVC 2 preview 2, and I have a question about the templates :

When I use Html.DisplayForModel(), the template used is the one which name is the same as my model type name : if my class name is "BlogPost" (for example), the template musst be in the file BlogPost.ascx.I didn't find how to change the default template used. I tried to use the UIHintAttribute to change the template, but it only works on properties, not on the class name.

Is there a way to change the default template for a class ?

Posted: Oct 15, 2009 08:35 PM

View 2 Replies!   View Related
Model Collections Of The Same Class Held By Several Other Classes?
How do I model the following using Castle ActiveRecord?

I have two classes, Customer and Task.

I would like to reuse a third class, Note, stored in a Collection in each of the Customer and Task classes.

[Code]....

I would then like to be able to pass the Notes collection to a Gridview, Listview or Repeater in the relevant ASP.Net page for the Customer or Task classes.

Posted: Nov 30 10 at 14:34

View 2 Replies!   View Related
ADO.NET :: How To Create Classes And Interfaces Using Entity Data Model
I am setting up my new project..We are using entity frame work 4.0..

Is there any wayto generate all classes and interfaces as we create manually for 3-tier architecture...

Or do i need to generate manually...

Ex:

Itest.cs
Public Interface ITest
{
int testproperty {get;set:}
}
Test.cs
Publicclass Test:ITest
{
public int testproperty {get;set:}
}

Posted: Jan 28, 2011 06:16 PM

View 1 Replies!   View Related
MVC :: To Put The Data Annotation Attributes - On The Viewmodel Classes Or On The Model?
I am using a model but as I want to have clean views I use the viewmodel approach which is like a downsized model which I map in my controller actions before sending to the view or getting it back in a HttpPost attributed action.

My question is: where to put the data annotation attributes. On the viewmodel classes or on the model? If I get it clearly the viewmodel annotations are used for the client side generation of validation right?

Do does that mean I have to put data annotations everywhere on both model and viewmodel?

Posted: Mar 20, 2010 02:26 PM

View 11 Replies!   View Related
MVC :: Creating Table Records With Foreign Key Constraints / Separate Controllers?
I have multiple tables that are all linked back to a central table with foreign keys. I want to be able to create a new record in table 2, but I'm having trouble because I don't know how to create a new instance of table 2's record while referencing the ID of the record it will be tied to.

EXAMPLE:

Database: Collection
Table: Collection Field 1: id Field 2: name
Table: Book Field 1: collectionId Field 2: id Field 3: name

Now, I don't want to be able to create a book without setting it's collectionID, but I can't figure out how this should be divided in the controllers/views.

Should Book have a controller separate from Collection, or should the Collection controller have a createBook method, separate from it's own create method?

I want to call the createBook method (from it's own controller, or the Collection controller) from the Collection Details view.

When I invoke the create method of Book, how do I create a new Book that is instantiated with the collectionId set from the details view of the Collection item that was listed in the details view?

I should point out, I'm using the entity framework for my model, and I'm definitely new to this.

Posted: Oct 03, 2010 10:12 PM

View 2 Replies!   View Related
SQL Server :: Creating Store Procedure - How To Insert The Primary Key From The Product_Table Into Theforeign Key
I have two tables. Product_Table withProductID as the primary key. My other table, ProductSKU_Table which has SKU as the primary key and ProductID as theforeign key. I am trying to create a store procedure to insert into both tables.How do I insert the primary key from the Product_Table into theforeign key of the ProductSKU_Table? This is what Ihave so far:

[Code]....

Posted: Aug 28, 2010 06:36 PM

View 15 Replies!   View Related
Best Practice For Creating/Using LinqToSql Classes?
I've recently discovered LinqToSql classes where you simply drag over tables from your datasource and it automatically generates psuedo classes that can be used.What is the best practice for creating/using LinqToSql classes?For instance, if my database contains 20 tables (assuming that the 5 table would be related to on another), should all these be dragged and contained within 1 LinqToSql.dbml? Or should it be separated into 4 dbml classes (all related tables in their respective dbml class)? Does having all of them in 1 dbml hurt performance?

Posted: Sep 18, 2009 04:36 PM

View 3 Replies!   View Related
ADO.NET :: Capture Updated / Changed Rows In The Entity Data Model Context Classes?
I am using an Entity Data Model (.edmx) in my project. I am using context.Customers to bind the grid.

Now when the datasource is binded to grid, i made some updates for 2 rows in the database.

Now, how can i capture those 2 updated rows in the context........?

Posted: Dec 16, 2010 03:41 AM

View 1 Replies!   View Related
Security :: Creating Entity Like Classes For MySQL?
I am starting to build a website project for personal use to learn ASP.NET more in depth. I am wanting to use MySQL as a database since I have a friend thats a MySQL admin guy at his job. But I only have Web Developer Express 2010 and cant get the MySQL plugin to use the Entity Framework with MySQL. So I was wanting to create my own classes for each table in my database with properties related to each column so that I can use something like the following:

[Code]....

I just dont know how to go about doing this or what to search for in Google to find info on this or if this is even possible.

Posted: Mar 13, 2010 09:03 PM

View 1 Replies!   View Related
Object Relational Designer Not Creating LINQ To SQL Classes?
I'm a complete .NET novice working my way through a book at the moment to get to grips with things.

I'm trying to use LINQ to SQL and create classes in Visual Web Developer 2008. This is what I've done:

- Right clicked on the app_code folder in my project, and gone to add > new item.

- Selected 'LINQ to SQL classes', called it 'MyDatabase.dbml'and clicked add

- This creates a file and opens up O/R designer.

- I then click 'database explorer', go to the one table I have in my database (Called 'Clients'), and drag it on to the design pane. I can then see the table and all it's properties.

However, I'm then expecting it to generate a .vb file in the app_code folder that is the LINQ to SQL entity. However, no such file seems to be created. I've built the app, and the files still don't seem to be generated. I'm confused, these are all the steps I have in my book, and all I can see in guides online, why doesn't it work?

Posted: Sep 23, 2009 09:14 PM

View 8 Replies!   View Related
DataSource Controls :: Entity FK Setup Via VS2010 / Working Enity Model With Foreign Keys Working?
Am trying to get a working enity model with foreign keys working but have run into a problem. I have imported 3 tables with content and some data.Lets call these tables geo_countries, geo_counties, geo_municipalities and the FK are:1. geo_county have a column country_id wich corresponds to country_id in geo_country2. geo_municipality have a column county_id wich correspond to the county_id ingeo_county.The problem i have is when i try to get correspondig child items with the following code i run into trouble:

[Code]....

The problem above is that 'test' generates results but not 'test2', wich never return anything. Am i not supposed to be able to do it like i do in 'test2'? I earlier tried to add a child object by replacing ToList() with Add() and that worked. But i cant seem to get anything out of it.

Posted: Jul 09, 2010 02:21 PM

View 4 Replies!   View Related
Getting Stared With .net 3.5 - Creating A DBML File And Create The Classes Of All The Tables?
I am new to ASP.net 3.5 . I want to make an appliaction of a job site in ASP.net 3.5. Please anybody guide me the best way to get stared with ASP.net 3.5. My Database has been created. Now, I dont know how to do the further the things in asp.net 3.5
.
shall i go for creating a DBML file and create the classes of all the tables. then use it from code behind file like linq to sql. or I should go for Entity Data model or something else i should use.

Posted: Oct 05, 2009 02:53 PM

View 15 Replies!   View Related
ADO.NET :: EF: Creating Database And Model?
This is a simplified example of what I need. Imagine a person table with several different club tables. Every person can belong to any number of clubs, but must belong to at least one club. The association would be a 1 to zero or one between the person table and each of the club tables.I've created the databases, then the entity model. The associations are all 1 to many, which isn't what I want.

Is there a way to modify the database so that the model is created correctly? I'm still building the project, making lots of changes, and I've had problems with updating the model, so I keep recreating it. Setting up the database correctly would be preferable.I'm trying to follow the quickstart here: [URL]but I'm using the SQL Management Studio designer, and I can't find how to fix the associations I add.

I've been reading about using or not using foreign keys in the model, but it's only confused me more. Can someone help me understand this? I'm starting to write code with what I have, and I'm running into problems. I'm about to start using joins, which means I'm trying to use a hammer instead of a saw because I don't know how to use my saw. I'd rather understand my tools and use them the right way!

Posted: Mar 25, 2011 03:00 PM

View 22 Replies!   View Related
MVC :: The Name 'Html' Does Not Exist In The Current Context / Not Recongnizing The Html And Model Classes?
I am working on an ASP.NET MVC 2 project with VS 2010 and out of nothing I get the following errors on my views:

The name 'Html' does not exist in the current context

The name 'Model' does not exist in the current context

It is like it is not recongnizing the MVC Html and Model classes.

I have System.Web.Mvc on my references and on Web.Config I have:

[Code]....

Posted: Apr 30, 2010 03:23 PM

View 2 Replies!   View Related
MVC :: Model Not Found When Creating A View?
Trying to create a strongly typed view but the model "that is a class" is not listed in the "View data class" dropdown?

Posted: Sep 03, 2010 07:45 PM

View 3 Replies!   View Related
Creating An External Link In MVC 2 From Model Properties?
I'm trying to build a link to an external website using some properties of my model class in my view page, e.g. I want it to render as something like -[URL]where post-id would be pulled from the model (I'm using a strongly typed view model here - I can't use ViewData as there's a list of items being pulled back all of which need seperate links).I tried doing < a href="<% model.PermaLink(); %>">, where PermaLink is just some string, however the value doesn't get picked up.If I try < a href="<%= model.PermaLink %>">, I get an error - CS1502: The best overloaded method match for 'System.IO.TextWriter.Write(char)' has some invalid argumentsIs there any way to do this? I tried adding the runat="server" attribute, however this just linked to my local site and controller/model actions.

Posted: Sep 13 10 at 20:07

View 2 Replies!   View Related
Creating A View And Updating An Entity Model?
EDIT: This question is vague and will likely be of little use to anyone. I am awarding internet monies to the gentleman below whom "helped" me.Sorry that the title is a little vague. I am still new to asp mvc & EF. Here is my issue. I have a DB somewhat like this.

Employee
- ID
- Name
- Address
EmployeeJob
- EmployeeID
- JobID
- StartDate
JobTypes
- ID
- JobName

I want a create form that will show all the Employee fields as well as a list of JobTypes for the users to be able to select. Then I will post the results back to the controller and update the DB. I have started looking into custom viewmodels, but am still unsure of exactly how to put that together and get it to work.

Posted: Mar 13 at 19:26

View 1 Replies!   View Related
MVC 2 Relation Without Foreign Key With Entity Framework 4 Or With Foreign Key?
1 - Is it necessary to have foreign key to obtain a Relation in Entity Framework between each entity.?
2 - I have a Language Table and many many table with a foreign key related to the language table. Is it right to add this foreign key or I should do something else ?
Ex:
Language
LangID
LangName

TableTextA
TblAID
TextInfo
LangID

TableTextB
TblBID
TextInfo
LangID

TableTextC
TblCID
TextInfo
LangID
etc ...

Posted: Sep 13 10 at 12:33

View 1 Replies!   View Related
ADO.NET :: Creating An Entity Data Model Filtered On A Session Variables (C#)
I'm trying to customize correct displaying of dropdownlists so information shown in comboboxes is relevant to the kind of user logged on (maintaining referential integrity at data level)

e.g.: I have a user already logged on and depending on his profile I'd like to display to this user only the portion of the database that he would be allowed to see. That would mean that he might have acces to an specific subset of data, e.g.: businesstype = "3", loging level = "2", etc.

Is there a way of creating an Ado.Net Entity Data Model filtered on a Session variables as to maintain proper referential integrity at data level?

Posted: Nov 01, 2010 05:43 PM

View 1 Replies!   View Related
MVC :: Creating A Class UserDetailsModel.cs In Folder Model./gettting An Error Message In Partial Rendering
I have created a class UserDetailsModel.cs in my folder model.I have populated a selectedList in the model class.

I have create a view which is both strongly-typed and partial and the view data class is the abc.cs

I have the following code in the view

[Code]....

However, i`m getting the error of
[Code]....
[Code]....

Posted: Jan 04, 2010 09:56 AM

View 10 Replies!   View Related
Visual Studio :: What Is The Difference Between Designer Classes And T4 Template Generated Classes
I am new to LINQ. when we drag tables we get a dbml file and designer file.

For example DataClasses1.dbml and DataClasses1.designer.cs.

Once we have them then we can start using our LINQ Queries.

In my company project I do not see this designer files and instead there are .tt files which were used as templates to greate ABC.generated.cs files. Is this same as designer class?

Posted: Jan 11, 2010 07:54 AM

View 3 Replies!   View Related
C# - Class Structure With LINQ, Partial Classes, And Abstract Classes
I am following the Nerd Dinner tutorial as I'm learning ASP.NET MVC, and I am currently on Step 3: Building the Model. One part of this section discusses how to integrate validation and business rule logic with the model classes. All this makes perfect sense. However, in the case of this source code, the author only validates one class: Dinner.

What I am wondering is, say I have multiple classes that need validation (Dinner, Guest, etc). It doesn't seem smart to me to repeatedly write these two methods in the partial class:

[code]....

This doesn't "feel" right, but I wanted to check with SO to get opinions of individuals smarter than me on this. I also tested it out, and it seems that the partial keyword on the OnValidate method is causing problems (understandably so). This doesn't seem possible to fix (but I could very well be wrong).

Posted: May 17 10 at 18:07

View 1 Replies!   View Related
C# - Can Base Classes See The Protected Fields Of Derived Classes
I don't know if this has to do with how FindControl works or how scope works. But my base class is having a hard time seeing the fields of child classes. Currently I'm planning have the derived class set a property in the base class, but there are a lot of derived classes, so that isn't a very attractive solution.

[code]....

Posted: Aug 11 10 at 18:27

View 4 Replies!   View Related
Web Forms :: Using C# Classes Vb Classes Together In VS2008 / 3.5 Project
Can I use VB and C# classes together in the same asp.net 3.5 project?

Posted: Mar 24, 2010 02:44 PM

View 3 Replies!   View Related
MVC :: Store Model In Separate Class Library- Pass Model Objects?
I'm building an MVC 2 RTM app, and I want to be able to share my model across applications. I'd *like* to be able to implement it like:ASP.NET MVC2 app (holds Views and Controllers)Class library to hold Model(s)WCF app to handle the data transactions with the models via different data stores across apps I had the MVC app working fine, but I wanted to abstract the data stuff and be able to work with the model across apps through the WCF site, so I created a class library project and moved all of the Models classes into that and set-up a WCF app, then added project references to the MVC and WCF apps that point at the class library. The idea was I can create services that take and return objects from the model via method calls across apps. It appears that everything's wired up correctly in the MVC project, so I'm passing the objects stored in the Models class library between controllers and views and everythig is compiling just fine, but for some reason the data is not being passed back from the views to the controller on POST -- all of the properties in the classes are null or empty.

When I debug the app, I can see that the values are stored in the model data dictionary but not the model object itself. What am I doing wrong? Am I on the wrong path, or missing something obvious (to some)?

Posted: May 19, 2010 09:57 PM

View 2 Replies!   View Related
MVC :: Access Model Validation Inside Custom Model Binder?
Is it possible, inside a Custom Model Binder, to fire "something" that "says" the value is invalid so it gets handled by validation part?

Basically, I am getting an exception when the value for the property is invalid.

Posted: Sep 01, 2010 07:23 PM

View 1 Replies!   View Related
ADO.NET :: Entity Model - Update Model From DB And The Assembly Reference Seems To Be Missing?
I made a few changes to the DB in SQL server management studio then right clicked on the .edmx doc to get it to update. That seemed to work fine but when i compiled the app everything thatreferenced the EF seems to be broken.The Error list now contains the below error for all classes that used it.

The type or namespace name '' could not be found (are you missing a using directive or an assembly reference?)

Posted: Jan 10, 2011 12:49 PM

View 4 Replies!   View Related
HttpHandlers / Modules :: Process Model Or Thread Model Of A Website?
I have an issue of static variable in an asp.net application. Let's say I have a server with 8 CPUs running windows 2008 R2 hosting an asp.net webbsite, nothing fancy here, no funny configuration.

Is the following statement true? at any single time, there's one and only one process is running and accepting requests, even in the recycling stage. The reason I am asking is: I have a static field in my class, and I want to make that's the only static instance in the website. I've heard in some circumstances, IIS is recylcing your application, and it will start a new process, but the old process is still working, thus I will have 2 static instances in memory, which defeat the purpose of static field.

One step further, let's assume there might be 2 instances in memory, can I assume there are at most 2 instances at any single time? And can I assume once the second instance is up, the first instance will NEVER accept new requests?

Another question: Recently I have a problem with an applicationdomain concept. Looks like if an application domain causes a memory leak, unload the domain will not release the memory (Umanaged leak). So to what extent Application Domain is isolated?

Posted: Mar 11, 2010 07:16 PM

View 1 Replies!   View Related
Copyright 2005-08 www.BigResource.com, All rights reserved