Entity Framework Join 3 Tables

I think it will be easier using syntax-based query: var entryPoint = (from ep in dbContext.tbl_EntryPoint join e in dbContext.tbl_Entry on ep.EID equals e.EID join t in dbContext.tbl_Title on e.TID equals t.TID where e.OwnerID == user.UID select new { UID = e.OwnerID, TID = e.TID, Title = t.Title, EID = e.EID }).Take(10); And you should … Read more

StringLength vs MaxLength attributes ASP.NET MVC with Entity Framework EF Code First

MaxLength is used for the Entity Framework to decide how large to make a string value field when it creates the database. From MSDN: Specifies the maximum length of array or string data allowed in a property. StringLength is a data annotation that will be used for validation of user input. From MSDN: Specifies the … Read more

How to include a child object’s child object in Entity Framework 5

If you include the library System.Data.Entity you can use an overload of the Include() method which takes a lambda expression instead of a string. You can then Select() over children with Linq expressions rather than string paths. return DatabaseContext.Applications .Include(a => a.Children.Select(c => c.ChildRelationshipType));

Getting exact error type in from DbValidationException

While you are in debug mode within the catch {…} block open up the “QuickWatch” window (ctrl+alt+q) and paste in there: ((System.Data.Entity.Validation.DbEntityValidationException)ex).EntityValidationErrors This will allow you to drill down into the ValidationErrors tree. It’s the easiest way I’ve found to get instant insight into these errors. For Visual 2012+ users who care only about the … Read more

The relationship could not be changed because one or more of the foreign-key properties is non-nullable

You should delete old child items thisParent.ChildItems one by one manually. Entity Framework doesn’t do that for you. It finally cannot decide what you want to do with the old child items – if you want to throw them away or if you want to keep and assign them to other parent entities. You must … Read more

What effect(s) can the virtual keyword have in Entity Framework 4.1 POCO Code First?

So far, I know of these effects. Lazy Loading: Any virtual ICollections will be lazy-loaded unless you specifically mark them otherwise. More efficient change tracking. If you meet all the following requirements then your change tracking can use a more efficient method by hooking your virtual properties. From the link: To get change tracking proxies, … Read more

Entity Framework Code First – two Foreign Keys from same table

Try this: public class Team { public int TeamId { get; set;} public string Name { get; set; } public virtual ICollection<Match> HomeMatches { get; set; } public virtual ICollection<Match> AwayMatches { get; set; } } public class Match { public int MatchId { get; set; } public int HomeTeamId { get; set; } public … Read more

Ignoring a class property in Entity Framework 4.1 Code First

You can use the NotMapped attribute data annotation to instruct Code-First to exclude a particular property public class Customer { public int CustomerID { set; get; } public string FirstName { set; get; } public string LastName{ set; get; } [NotMapped] public int Age { set; get; } } [NotMapped] attribute is included in the … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)