TECHNOLOGIES
FORUMS
JOBS
BOOKS
EVENTS
INTERVIEWS
Live
MORE
LEARN
Training
CAREER
MEMBERS
VIDEOS
NEWS
BLOGS
Sign Up
Login
No unread comment.
View All Comments
No unread message.
View All Messages
No unread notification.
View All Notifications
Answers
Post
An Article
A Blog
A News
A Video
An EBook
An Interview Question
Ask Question
Forums
Monthly Leaders
Forum guidelines
Matt Butler
NA
18
0
LINQ types failing in MVC3
Jan 31 2012 3:18 PM
Hello everybody. I have been coming here quite a while for help and never needed to post a question until now. I am currently building my first MVC3 web application in C#. To be perfectly honest with you, I am new to C# as well. I have built a program here and there, but I usually do not program in C#. I am not completely new to programming, I have been programming in VB.NET for years...
Let's get into my actual question. I have already built a program in VB.NET that uses a SQL back-end. The program allows remote sites to send requests to the corporate office. This program has been working very well. Remote administrators on the other hand, are finding it too difficult to login to the VPN and approve requests, so they would like a website created. I have been following along in the tutorials on the asp.net/mvc website, but I am lost right now and require some assistance. I think my previous database design may be messing me up big time.
I have several tables in my database. One of the tables is a table of status messages that are used. The table looks like this:
StatusID (int)
ShortMessage(varchar(50))
LongDescription(varchar(max))
1
Some short status
Some long description of the short status
2
Another short status
Another long description of the short status
3
etc
etc
Now, I have other tables built with a RequestStatus column that references the StatusMessages table. Therefore, if I have a RequestStatus of 2, I perform a join in my program and do a lookup on the StatusMessages table to find what the status is.
One problem is that the RequestStatus column in all my other tables is a varchar and I think that may be causing an issue with LINQ. Here is my code so far in MVC.
ButtonRequest Model:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.ComponentModel.DataAnnotations;
using System.ComponentModel;
namespace BFLmvc3Int.Models
{
public class ButtonRequest
{
public virtual int ID { get; set; }
public virtual string UserID { get; set; }
public virtual string RequestorName { get; set; }
public virtual string RequestText { get; set; }
public virtual string RequestorEmail { get; set; }
public virtual string FirstApproverEmail { get; set; }
public virtual string FirstApproverText { get; set; }
public virtual string SecondApproverEmail { get; set; }
public virtual string SecondApproverText { get; set; }
public virtual string ThirdApproverEmail { get; set; }
public virtual string ThirdApproverText { get; set; }
public virtual string RequestStatus { get; set; }
public virtual string RevCenter { get; set; }
public virtual string RequestJustification { get; set; }
public virtual DateTime? FirstApproverTimeStamp { get; set; }
public virtual DateTime? SecondApproverTimeStamp { get; set; }
public virtual DateTime? ThirdApproverTimeStamp { get; set; }
[DataType(DataType.Date)]
[DisplayName("Start Date:")]
[DisplayFormat(DataFormatString = "{0:MM/dd/yyyy}", ApplyFormatInEditMode = true)]
public virtual DateTime StartDate { get; set; }
[DataType(DataType.Date)]
[DisplayName("End Date:")]
[DisplayFormat(DataFormatString = "{0:MM/dd/yyyy}", ApplyFormatInEditMode = true)]
public virtual DateTime EndDate { get; set; }
}
}
Status Messages:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.ComponentModel.DataAnnotations;
using System.ComponentModel;
namespace BFLmvc3Int.Models
{
public class StatusMessages
{
public virtual int ID { get; set; }
public virtual string ShortMessage { get; set; }
public virtual string LongDescription { get; set; }
}
}
Button Request Controller:
public class ButtonRequestController : Controller
{
private FormsLib db = new FormsLib();
//
// GET: /ButtonRequest/
public ViewResult Index()
{
var result = from br in db.ButtonRequest
join sm in db.StatusMessages on br.RequestStatus equals sm.ID
where sm.ID < 3
select br;
return View(db.ButtonRequest.ToList());
}
I am receiving the following error during compile time:
Error1The type of one of the expressions in the join clause is incorrect. Type inference failed in the call to 'Join'.C:\Users\mbutler\documents\visual studio 2010\Projects\BFLmvc3Int\BFLmvc3Int\Controllers\ButtonRequestController.cs2326BFLmvc3Int
Reply
Answers (
2
)
Problem in using Lambda expressions
Combining multiple sequences into 1 object