Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trialRohit Gopalan
81,945 PointsUnable to get the Data Annotation for Entity working
I tried to add the annotations for the Title property for the Course entity. But it results in compiler errors. It would be great if someone can identify the compiler issue and suggest how to overcome it.
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;
namespace Treehouse.CodeChallenges
{
public class Course
{
public Course()
{
Students = new List<CourseStudent>();
}
public int Id { get; set; }
public int TeacherId { get; set; }
[Required, StringLength(20), Column("Title",TypeName="nvarchar(20)")]
public string Title { get; set; }
public string Description { get; set; }
public int Length { get; set; }
public Teacher Teacher { get; set; }
public ICollection<CourseStudent> Students { get; set; }
}
}
2 Answers
Edward Ries
7,388 Points[Required, StringLength(20), Column("Title",TypeName="nvarchar(20)")]
I've never seen an attribute called Column. Maybe it's something new but for this challenge if you remove column and set the StringLength to 200 then it will pass the challenge.
[Required, StringLength(200)]
Michael Fazio
15,586 PointsEd, that worked! Thanks! This question was throwing me for a loop as well!