I needed to get essentially a summary by case statement for a given date. As you can see I have defined the MAX date into a variable. This example also shows using a substring of the first character in a LET statement DateTime? maxDate = (from a in context.tbl_tslog orderby a.CurrentTime select (DateTime?) a.CurrentTime ).Max(); var dbRecords = (from c in context.tbl_testlog where (c.CurrentTime >=maxDate) let range = ( c.Usr.ToUpper().Substring(0,1) == "B" ? "US" : ...
One of the issues with using Entity Framework is that you may want some special annotation but you don't want to use a DTO or other object outside of EF. One way to afford you the opportunity to Annotate on the original EF model is to extend with a partial class of meta data. In your Data Models folder (or really anywhere in your data project) you would add a class (Partial Classes) that would contain empty pointers to your data classes - (in my tt files I have a company class and a systemUser class which represent models from the tables in my database): PartialClasses.cs using System.ComponentModel.DataAnnotations; namespace MySite.Data { [MetadataType(typeof(systemUsersMetadata))] public partial class systemUser { } [MetadataType(typeof(companyMetadata))] public partial class company { } } Once you have this setup you can begin to annotate! Create a system...
Comments