entity-framework-4.1

Multiple Primary Key with asp .net mvc 3

拟墨画扇 提交于 2019-12-18 12:04:32
问题 I'm using asp .net mvc 3, and I have a problem with an entity that contains 2 primary key, when I try to insert data in the table. public class LineItem { [Key] public int OrderId { get; set;} [Key] public int LineNum { get; set;} public string ItemId { get; set;} public int Quantity { get; set;} public decimal UnitPrice { get; set; } } when I try to insert I got this error : Unable to determine composite primary key ordering for type 'ApplicationMVC3.Models.LineItem'. Use the ColumnAttribute

Best way to handle concurrency with entity framework

别来无恙 提交于 2019-12-18 10:29:18
问题 I am using entity framework 4.1.What is the best way to handle concurrency with entity framework. Is there inbuilt functionality to handle it in entity framework? Can I do without adding extra column to the tables to keep row version? 回答1: Have you seen this tutorial: http://www.asp.net/entity-framework/tutorials/handling-concurrency-with-the-entity-framework-in-an-asp-net-mvc-application You can do it without a rowversion column but that often requires storing a lot of state, which can

How can l use Entity Framework without App.config

末鹿安然 提交于 2019-12-18 08:57:43
问题 I want to use Entity Framework without app.config file. I want to define a string variable Connection String in my code and use that to connect to the database. Please show me the way if it is possible. 回答1: You're not mentioning what approach you're using (database-first, model-first, code-first) - but basically, in the end, you need to define a string variable and assign it a valid EF connection string string myConnectionString = "...(define a valid EF connection string here)......";

Include with projection does not work

筅森魡賤 提交于 2019-12-18 08:55:34
问题 I have this query var test = context.Assignments .Include(a => a.Customer) .Include(a => a.Subscriptions) .Select(a => new AssignmentWithSubscriptionCount { SubscriptionCount = a.Subscriptions.Count(), Assignment = a }) .ToList(); var name = test.First().Assignment.Customer.Name; It failes to eagerly load Customer, I've seen similar problems here on stackoverflow and it looks like you cant use projections with include. But I have not found a solution to my problem.. Anyone? edit: Here is a

Entity Framework and DbContext - Object Tracking

杀马特。学长 韩版系。学妹 提交于 2019-12-18 07:14:10
问题 I am a bit confused on the usage of DbContext in Entity Framework. Here's the scenario I'm confused about. I use a linq query from the dbcontext to get data. Something like: List<Transactions> transactions = DefaultContext.Transactions.ToList(); Then I update a column in one of the transactions returned in that query directly in the database. Then I call again: List<Transactions> transactions = DefaultContext.Transactions.ToList(); When the list returns back this time, it doesn't reflect the

Class Inheritance with .NET EF4.1 + MySQL

我怕爱的太早我们不能终老 提交于 2019-12-18 05:11:30
问题 I'm trying to implement class inheritance in .NET using Entity Framework 4.1 and MySQL as database, with code-first approach. The model below works with SQL Server, but fails in MySQL with the following error: Schema specified is not valid. Errors: (11,6) : error 0064: Facet 'MaxLength' must not be specified for type 'mediumtext'. The model is a classic simple example: public abstract class Vehicle { public int Id { get; set; } public int Year { get; set; } } public class Car : Vehicle {

how do I sort a collection with child property?

…衆ロ難τιáo~ 提交于 2019-12-18 04:16:31
问题 I should sort parent based on a field of child. sample code; IQueryable<Parent> data = context.Parents.Include(o=>o.Children); //Child has a member (string) Name. question: how can I sort Parent by Children Names. 回答1: Your question is somewhat confusing, since first of all, it is tagged both with Entity Framework and LINQ-to-SQL. Which ORM are your actually using? Secondly, and more to the point, you say that you want to "sort Parent by Children Names" . Which child name do you want to sort

SQL “not in” syntax for Entity Framework 4.1

走远了吗. 提交于 2019-12-18 01:56:46
问题 I have a simple issue with Entity Framework syntax for the "not in" SQL equivalent. Essentially, I want to convert the following SQL syntax into Entity Framework syntax: select ID from dbo.List where ID not in (list of IDs) Here is a method that I use for looking up a single record: public static List GetLists(int id) { using (dbInstance db = new dbInstance()) { return db.Lists.Where(m => m.ID == id); } } Here is a pseudo-method that I want to use for this: public static List<List> GetLists

SQL “not in” syntax for Entity Framework 4.1

不想你离开。 提交于 2019-12-18 01:56:21
问题 I have a simple issue with Entity Framework syntax for the "not in" SQL equivalent. Essentially, I want to convert the following SQL syntax into Entity Framework syntax: select ID from dbo.List where ID not in (list of IDs) Here is a method that I use for looking up a single record: public static List GetLists(int id) { using (dbInstance db = new dbInstance()) { return db.Lists.Where(m => m.ID == id); } } Here is a pseudo-method that I want to use for this: public static List<List> GetLists

Entity Framework: Tracking changes to FK associations

送分小仙女□ 提交于 2019-12-18 01:21:36
问题 I'm overriding SaveChanges on my DbContext in order to implement an audit log. Working with many-to-many relationships or independent associations is relatively easy as EF creates ObjectStateEntries for any changes to those kinds of relationships. I am using foreign key associations, and when a relationship between entities changes all you get is an ObjectStateEnty that says for example entity "Title" has "PublisherID" property changed. To a human this is obviously a foreign key in Title