views:

75

answers:

1

I'm trying to use SubSonic 3.0 with SQLite 3 in ASP.NET MVC. After initial pains of setting it up I am finally able to retrieve data from my single (so far) table database, however I never get a value for the Testimonial column. I tried renaming it to something like TestimonialText, I tried changing its data type to VARCHAR, NVARCHAR with different sizes and w/o an explicit size and even TEXT. Nothing works. I can query the database (using SQLite Administrator) and see the results - both in the grid and with manually written queries. I'm totally cluless as to what's happening. Here's some code:

Database

CREATE TABLE [Testimonials] (
[ID] INTEGER  PRIMARY KEY AUTOINCREMENT NOT NULL,
[Referral] NVARCHAR(30)  NOT NULL,
[Role] NVARCHAR(20)  NULL,
[Company] NVARCHAR(100)  NOT NULL,
[Url] VARCHAR(255)  NULL,
[Testimonial] NVARCHAR(500)  NOT NULL
)

Controller action

public ActionResult Index()
{
    // Get all testimonials.
    var testimonials = Testimonial.All();

    // Pick a random one.
    var count = testimonials.Count();
    var rnd = new Random().Next(count);
    var testimonial = testimonials.Skip(rnd).Take(1).Single();
    ViewData["Testimonial"] = testimonial;

    return View();
}

View

<%= Html.Encode(Model.TestimonialX) %><br />
<%= Html.Encode(Model.Referral + ", " + Model.Role) %><br />
<a href="<%= Model.Url %>"><%= Html.Encode(Model.Company) %></a>

All fields display their proper values, except TestimonialX, which returns NULL. WHY?!

+2  A: 

The problem is that you have a column with the same name as the table and our Linq translator doesn't like it (something I'll be trying to fix in the coming weeks). If you rename this column (which is good practice anyway) it will work.

Rob Conery
Thanks. I tried changing the name before, however I did not notice an error in the SQLite Administrator and thought that SubSonic did not do its job. That definitely helps!
Pawel Krakowiak