entity-framework-5

Dynamically select which table to insert data into with entity framework

一笑奈何 提交于 2019-12-13 19:18:32
问题 So I am writing an application which need to select an entity at run time and add through the entity framework save this to a database, I have created the database and a model based off it through the use of an ADO.NET Entity Data model, the objects, which hold the data are chosen baised on the data that is being added at runtime with the use of the reflection class, as follows; mytype = Type.GetType(objName); myObject = Activator.CreateInstance(mytype); How can I do something like this to

Entity Framework Code First Update a Single Property of a Complex Type

怎甘沉沦 提交于 2019-12-13 16:45:17
问题 I am having a weird behavior. I want to update a single property of a complex type. When I specify properties to be updated with IsModified (some property are to true and some to false) I have nothing updated. If I specify no property of the complex type, every field of the complex property are updated. public class MyEntity { public MyComplexClass Property1 { get; set; } } //... The code below doesn't work, in fact it update nothing var entityLocal = this.Set<MyEntity>().Local

Entity Framework 1-1 relationship is not persisting data to the database

别来无恙 提交于 2019-12-13 16:27:26
问题 I've got a table FeeMetadata with a PK FeeID BIGINT IDENTITY(1,1) NOT NULL This table contains two 1-1 relationships. One to PFD.Fees , and one to SoaCourt.Fees via the FeeID column (same name in all three tables, only the metadata table is marked as IDENTITY, the other two tables this column is PK but NOT identity) Here's the code for the EF classes: Namespace PFD <Table("FeeMetadata", Schema:="PFD")> Public Class FeeMetadata Public Sub New() MyBase.New() End Sub Public Sub New(ByVal tFee As

EntityTypeConfiguration how to get the key property?

限于喜欢 提交于 2019-12-13 16:24:16
问题 I am using c#, with EF 5 and MVC4 I am using EntityTypeConfiguration to set up the primary key and the backend table public class AuditZoneMap : EntityTypeConfiguration<AuditZone> { public AuditZoneMap() { // Primary Key HasKey(t => t.Id); // Properties Property(t => t.Description) .HasMaxLength(100); // Table & Column Mappings ToTable("AuditZone"); Property(t => t.Id).HasColumnName("Id"); Property(t => t.Description).HasColumnName("Description"); Property(t => t.Valid).HasColumnName("Valid")

Sequential(Gapless) Invoice Number Creation

∥☆過路亽.° 提交于 2019-12-13 07:14:38
问题 We have implemented a webapplication for Billing system.I have a string column to store invoice number. This column has to forbid gap between number. Id InvoiceNumber(Desired) InvoiceNumber(Actual) 1 001 001 2 002 002 3 003 005 In pseudo-code using (TransactionScope _ts = new TransactionScope()) { var _lastGeneratedRecDetails = _db.StudentReceipts .Where(r => r.Status == true && r.StudentRegistration.StudentWalkInn.CenterCode.Id == _centreCodeId && EntityFunctions.TruncateTime(r.DueDate.Value

making database call asynchronous in EF

末鹿安然 提交于 2019-12-13 06:13:24
问题 I am using EF 5.0 and have a question on making the Database calls asynchronous. To begin with below is the autogenerated method call in contextModel>.context.cs public virtual ObjectResult<InstructorsComplex> GetInstructors(string nm, string cd, string grp_cd) { var nmParameter = nm != null ? new ObjectParameter("nm", nm) : new ObjectParameter("nm", typeof(string)); var cdParameter = cd != null ? new ObjectParameter("cd", cd) : new ObjectParameter("cd", typeof(string)); var grp_cdParameter =

IdentityDbContext how to run migrations

◇◆丶佛笑我妖孽 提交于 2019-12-13 05:24:00
问题 I am new to Entity-Framework-5 and IdentityDbContext, I have managed to create my and create the AspNet membership tables,then i changed the type in one of the properties of the model, now my project wont run and its telling me that I need to run migrations. My question is, how to run migrations on the IdentityDbContext? I cant find any good guides on how to do it. Additional information: The model backing the 'ApplicationIdentityUserDbContext' context has changed since the database was

Why can't my .NET 4.5 project use a DLL compiled for .NET 4? (Both use EF 5)

≯℡__Kan透↙ 提交于 2019-12-13 05:19:33
问题 I have an application that consists of a client-side application and a WebApi website. My client-side stuff is targetting .NET 4 so that I don't have to insist that users install .NET 4.5. My website, however, is entirely under my control, so I'm targetting .NET 4.5. There is one shared assembly, which I use for data access. It uses Entity Framework 5. When I build the client application, the DLL used is version 4.4.xxx, whereas when I build the web application, the DLL is 5.0.xxx. Up until

Specification Testing with EF - The ObjectContext instance has been disposed

让人想犯罪 __ 提交于 2019-12-13 05:19:27
问题 I have the following SpecFlow scenario: [When(@"the registration is submitted")] public void WhenTheRegistrationIsSubmitted() { //var controller = _kernel.Get<AccountController>(); var factory = new HockeyDbContextFactory(); var userRepository = new Repository<User>(factory); var cryptoService = new CryptoService(); var roleRepository = new Repository<Role>(factory); var playerService = new Mock<IPlayerService>(); var leagueService = new Mock<ILeagueService>(); var userService = new

Mapping Many-to-Many Relationship With Defined Middle Entity in Entity Framework 5

岁酱吖の 提交于 2019-12-13 04:12:39
问题 I'm trying to define a many-to-many relationship explicitly. By explicitly, I mean that I'm defining the middle entity and configuring it using the Fluent API. Below is my code: public class ContentType { public Int64 Id { get; set; } public Guid SID { get; set; } public String Name { get; set; } public ContentType Parent { get; set; } public Nullable<Int64> ParentId { get; set; } public Category Category { get; set; } public Nullable<Int64> CategoryId { get; set; } public Boolean IsLocked {