entity-framework-6

Insert/Update data to Many to Many Entity Framework . How do I do it?

对着背影说爱祢 提交于 2019-12-04 21:18:40
My context is => Using this model via Entity Framework code 1st, data table in database becomes => 1) User Table 2) Role Table 3) UserRole Table - A new linked table created automatically Model for User is => Model for Role is => and my O Data query for inserting record for single User/Role table working properly Now, what query should I write, when I want to Insert record to UserRole table can someone have any idea // Fetch the user. var user = await metadataManagentClient.For<User>().FirstOrDefaultAsync(x => x.Name == "Test"); // If you want to add a new role. var newRole = new Role() { Name

Changing primary key data type in Production DB

白昼怎懂夜的黑 提交于 2019-12-04 20:32:08
I am using EF code-first. I need to change the datatype of primary key of one table in our production database. public class Course { [Key] public Guid Id {get; set;} //This needs to be changed to int public string Name {get;set;} public virtual ICollection<Group> Groups {get;set;} } public class Group { [Key] public Guid Id {get; set;} public string Name {get;set;} public virtual ICollection<Course> Courses{get;set;} } As the above is a Many-Many relationship, EF has created a join table GroupCourses automatically with PK & FK as both Group_Id and Course_Id . Which is fine until now. Now I

Entity Framework 6 - inheritance and navigation properties on base class

☆樱花仙子☆ 提交于 2019-12-04 19:06:16
I have a problem with navigation properties and inheritance. This is my problem: I have a base Person class and classes User and Worker which inherit from Person . On the DB level I'm using single table inheritance or table per hierarchy (TPH) inheritance. So there a single table with a discriminator column. Both User and Worker need to have a Company relation, so I would like to define it on the Person class. I define my model like this: [Table("mydb.person")] public abstract partial class Person { [Key, DatabaseGenerated(DatabaseGeneratedOption.Identity)] public long ID { get; set; } public

Entity Framework - Non Key Relationships

一笑奈何 提交于 2019-12-04 18:57:57
Problem I have a situation whereby I need to use Entity Framework 6, Code First, with a legacy database structure which cannot be changed. The database has a very generic table which stores text based data alongside some non key data which can be used to relate the record back to another table. To illustrate: Assume the Notes table has a model as follows: [Table("Notes")] public class Notes { [Key] public int RecordId { get; set; } [Required] public string RelatedTableName { get; set; } [Required] public int RelatedTableRecordId { get; set; } [Required] public string NotesText { get; set; } }

Buildserver can not find Entity Framework Sql Provider

梦想与她 提交于 2019-12-04 18:43:42
问题 We are in the process of switching from Entity Framework 4 to Entity Framework 6. The package manager did its job, and the solution ran it’s tests without a hitch. However on the build server we get the following error message running the tests: Initialization method xxx.SetUp threw exception. System.InvalidOperationException: The Entity Framework provider type 'System.Data.Entity.SqlServer.SqlProviderServices, EntityFramework.SqlServer' registered in the application config file for the ADO

How do I resolve issues with unsupported DateTimeOffsets in EF 6 using Sql Server?

社会主义新天地 提交于 2019-12-04 18:34:46
When I try to instantiate a DbContext I receive this message: System.NotSupportedException: There is no store type corresponding to the conceptual side type 'DateTimeOffset' of primitive type 'DateTimeOffset'. I am using Entity Framework version 6 on SQL Server. The constructor of the DbContext (with the line that throws the exception) looks like this: internal TestHubContext(string connectionStringName) : base(connectionStringName) { var objectContext = (this as IObjectContextAdapter).ObjectContext; ... } The entities are created using code-first, and look like this: public class Order { [Key

Call multiple service method in one transaction

做~自己de王妃 提交于 2019-12-04 17:42:56
Forgive me I am not good at EF6. If I make some mistake . Please help me to correct it. Thanks. Firstly I want to implement the business logic in my service layer like below. public class userService { void createWithCommit(User user) { MyEntityContext db= new MyEntityContext (); ... db.Users.add(user);//Add a new user entity .... Work w = new Work(); ... db.Works.add(w);//Add a new work entity db.savechanges();//commit the changes which will insert 2 new record . one is user . another is work. } } But in some service class I want to call multiple others service method in one transaction like

EntityFramework 6 How to get identity-field with reflection?

夙愿已清 提交于 2019-12-04 17:26:06
问题 I have a generic method with type parameter T, where T is the type of entity in EF model. I need to get the name of identifying field in this type. I saw this article: Is there a way to get entity id-field's name by reflection or whatever? But I can't understand, what Tevin talking about when he talks about EntitySetBase and EntityTypeBase types. If EntityTypeBase is type of one of the entities in model, so then EF6 have no property KeyMembers . 回答1: I don't think it's possible to get the

How to parameterize a selector with a function in EF query?

妖精的绣舞 提交于 2019-12-04 16:24:23
I have a projection function that I pass to IQueryable<>.Select() method: private static Expression<Func<VendorPrice, PriceItem>> GetPriceSelector(){ return e => new PriceItem { Id = e.Id, Price = Math.Round(e.Price, 4) }; } Everything works just fine but I want to parameterize it like that: private static Expression<Func<VendorPrice, PriceItem>> GetPriceSelector(Func<VendorPrice, decimal> formula){ return e => new PriceItem { Id = e.Id, Price = formula(e) }; } so that I can call it like prices.Select(GetPriceSelector(e => Math.Round(e.Price, 4))) Unfortunately, EF complains about it: The LINQ

Table 'DBNAME.dbo.TableNAME' doesn't exist Entity Framework 6 with MySQL

断了今生、忘了曾经 提交于 2019-12-04 15:03:10
I am using Entity Framework 6.0.0 with MySql Server 5.6.17 I have added MySql.Data.Entities through nuget and it installed Entity Framework 6.0.0 and MySql.Data 6.8.4 Everything was setup perfectly and working fine with some of my Business Entities. it have automigration enabled(true). Later i have added some more entities and then it started giving error like Table 'DBNAME.dbo.TABLENAME' doesn't exist Entity Framework 6 I have tried deleting whole database and recreate it again, but it didn't worked. I have tried updating Entity Framework to 6.1.2 and MySql.Data to 6.9.5 but it did not solved