ef-code-first

define scalar function with ef4.1 code first?

醉酒当歌 提交于 2019-12-08 20:06:29
i have a function called distancebetween i wnat to define it in scalar valued function to call it by linq if there is away to do that by EF4.1 code first ? No. Code first was designed as "code first" = you will create a code and it will create a database where no database logic exists (no views, stored procedures, triggers or functions). Because of that it is completely missing features for mapping database logic like functions and stored procedures. If you want to use it in LINQ you must abandon code-first / fluent-API and start tu use EDMX where this is supported. Using ExecuteSqlCommand and

Mapping TPT in EF Code First 4.1 w/ Different Primary Keys

北城以北 提交于 2019-12-08 19:43:58
问题 I am trying to map a TPT inheritance hierarchy on a legacy database (I can't change column names). All of the examples have the primary keys of the parent and children tables with the same name. Unfortunately, mine doesn't behave this way. As a simplified example: Vehicle ---------------- VehicleId Make Model ---------------- Car ---------------- CarId SomeOtherField ---------------- CarId and VehicleId are actually the same id and are the values that should be used to associate the tables.

Does AsQueryable() on ICollection really makes lazy execution?

本小妞迷上赌 提交于 2019-12-08 19:21:07
问题 I am using Entity Framework CodeFirst where I have used Parent Child relations using ICollection as public class Person { public string UserName { get;set} public ICollection<Blog> Blogs { get; set;} } public class Blog { public int id { get; set; } public string Subject { get; set; } public string Body { get; set; } } Ok, so far everything is working ok, but my concern is, whenever I want to get the Blogs of a person, I get it as var thePerson = _context.Persons.Where(x => x.UserName = 'xxx'

This SqlTransaction has completed; it is no longer usable. Entity Framework Code First

馋奶兔 提交于 2019-12-08 19:18:35
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Data.SqlClient; using System.ComponentModel.DataAnnotations; using System.Data.Entity; namespace SqlEFTester { class Program { static void Main(string[] args) { ConnectionManager connectionManager = new ConnectionManager(); SqlConnection conn = connectionManager.Connection; conn.Open(); //BEGIN TRAN SqlTransaction tran = conn.BeginTransaction(); //Will do some legacy work using SqlTransaction, so can not use TransactionScope here. MyContext context = new MyContext(conn); List<Inventory> list =

Entity Framework 6 inserting duplicate values

被刻印的时光 ゝ 提交于 2019-12-08 19:16:00
问题 I have following two entities: public class Artist { [Key] public string ArtistId { get; set; } public string Name { get; set; } public virtual ICollection<Genre> Genres { get; set; } } public class Genre { [Key] public int GenreId { get; set; } public string Name { get; set; } public virtual ICollection<Artist> Artist { get; set; } } In my program I create some artists and want to save them: using (var context = new ArtistContext()) { var artists = _fullArtists.Select(x => x.Artist); foreach

Why `DatabaseGenerated(DatabaseGeneratedOption.Identity)` doesn't work in MVC 4

主宰稳场 提交于 2019-12-08 16:29:29
问题 I was trying to move my MVC 3 project to MVC 4 but when I wanted to move this model: public class Link { [DatabaseGenerated(DatabaseGeneratedOption.Identity)] public Guid ID { get; set; } [DisplayName("Shorted URL")] public string SURL { get; set; } [DisplayName("General Link")] public string OriginalURL { get; set; } [DisplayName("Click Count")] public int ClickCount { get; set; } } public class LinkDBContext : DbContext { public DbSet<Link> Links { get; set; } } I got error with [System

How Do I Resolve “A specified Include path is not valid”?

馋奶兔 提交于 2019-12-08 16:25:35
问题 I have a parent-child relationship setup that is fairly basic. The end result is that I want to be able to return the resulting tables as JSON through ASP.NET MVC WebAPI. I am using Entity Framework 5.0 beta 2. I can demonstrate the error I'm running into with a simple example. Given the classes Category and Product with the corresponding data context: public class Category { public int CategoryId { get; set; } public string Title { get; set; } public virtual IEnumerable<Product> Products {

What does EntityFramework Code First do with property getters/setters?

风格不统一 提交于 2019-12-08 15:40:16
问题 What exactly does the EntityFramework do to map properties that have custom getters and setters when using Code First? Does it simply call the getter for a property when serializing, and the setter when deserializing? So I could do something silly like... public class Foo { public DateTime TimeAccessed { get { return DateTime.Now; } set { TimeDeserialized = DateTime.Now; } } [NotMapped] public DateTime TimeDeserialized { get; private set; } } Note I have no actual interest in using the above

EF Code First 5.0.rc Migrations doesn`t update Identity property

Deadly 提交于 2019-12-08 15:27:37
问题 Say, we are using EF Code First and we have this simple model: using System; using System.Collections.Generic; using System.ComponentModel.DataAnnotations; using System.Data.Entity; using System.Linq; using System.Web; namespace EFCodeFirstIdentityProblem.Models { public class CAddress { public int ID { get; set; } public string Street { get; set; } public string Building { get; set; } public virtual CUser User { get; set; } } public class CUser { public int ID { get; set; } public string

EF 4.1 Referential integrity error

99封情书 提交于 2019-12-08 15:27:13
问题 I have the following classes: public class Person { [Key] public Guid Id { get; set; } [Required] public string FirstName { get; set; } [Required] public string LastName { get; set; } [Required] public string Email { get; set; } public virtual Survey Survey { get; set; } } public class Survey { [Key] public Guid Id { get; set; } public bool IsFinished { get; set; } public virtual ICollection<UserAnswer> UserAnswers { get; set; } public virtual Person Person { get; set; } } public class