entity-framework-4

EF IQueryable extension method not working in Select [duplicate]

a 夏天 提交于 2019-12-13 08:29:43
问题 This question already has answers here : Closed 7 years ago . Possible Duplicate: LINQ to Entities does not recognize the method I use Entity Framework 4.3 I write extension method: public static IQueryable<TSource> Active<TSource>(this IQueryable<TSource> source) where TSource : class, IStatusable { return source.Where(s => s.Status == (int)StatusEnum.Enabled); } This works good: var cat=Context.Categories.Active().ToList() But i need use this extension method in Select. Look simplified

UDT as a parameter in EF4 query

别说谁变了你拦得住时间么 提交于 2019-12-13 07:43:20
问题 I know that EF4 does not support User Defined Table Types (yet). I need to write a query, that accepts a list of pairs <product_code, quantity> and returns a record set with product_code and price for each product_code passed, based on quantity . What is my best option with EF4 to model this? The calculation in the database to get the price are quite complex, and there are a lot of products, which means that most of the action should happen server-side. (For example I can't get full list of

with ef 4.1 code first how can i create a nullable column

馋奶兔 提交于 2019-12-13 07:42:52
问题 I have the following POCO: Public Class T1 <Required()> <MaxLength(128)> <Key(), Column(Order:=0)> Property K1 As String <Required()> <MaxLength(128)> <Key(), Column(Order:=1)> Property K2 As String <Required()> Property C1 As String Property C2 As String end Class I would expect C2 to be created as Nullable, but both C1 and C2 are Not Null. Adding <Required(AllowEmptyStrings:=True)> Does not make a difference, as it seems the decoration is aimed at data validation, not DB creation. So how do

Entity Framework - Inheritance - Zero to one Relationship to child object, how to map? (Fluent API)

邮差的信 提交于 2019-12-13 07:10:40
问题 I have a Inheritance Hierarchy where Action is parent of ActionCompleted and ActionCancelled. Order class has a zero to one ActionCompleted and ActionCancelled. I have tried TPH and TPT (even tried edmx) but unable to get Entity to understand this relationship between Order and child actions, please suggest how do I map? //Classes public class Order { public int OrderId { get; set; } public string Name { get; set; } public ActionCompleted ACO { get; set; } public ActionCancelled ACA { get;

Where Clause With Null Object Using Entity Framework v5.0RC

£可爱£侵袭症+ 提交于 2019-12-13 07:01:51
问题 I was trying to do the following public IList<Category> GetMainCategories() { return _context.Category .Where(x => x.ParentCategory == null) .OrderBy(x => x.SortOrder) .ToList(); } However, no matter what I try this returns no results even though I can see in the collection that ALL ParentCategory's are null? I have read EF has problems with nulls like this and have also tried .Where(x => x.ParentCategory.Equals(null)) And .Where(x => Equals(x.ParentCategory.Id, null)) .Where(x => Equals(x

Entity object cannot be referenced by multiple instances of IEntityChangeTracker

时光毁灭记忆、已成空白 提交于 2019-12-13 06:13:41
问题 I am having below mentioned POCO classes. public class AppointmentModel { public InvoiceDetail InvoiceDetails { get; set; } public Invoice Invoice { get; set; } } public class InvoiceDetail { public Invoice Invoice { get; set; } } public class Invoice { public Invoice() { Id = Guid.NewGuid(); Created = DateTime.Now; } public Guid Id { get; set; } public virtual Appointment Appointment { get; set; } } I have tried to add that model inside repository is as below. public void Booking

Returning DbQuery to view that requires IEnumerable

与世无争的帅哥 提交于 2019-12-13 06:07:41
问题 The problem: Exception Details: System.InvalidOperationException: The model item passed into the dictionary is of type 'System.Data.Entity.Infrastructure.DbQuery`1[System.Int32]', but this dictionary requires a model item of type 'migros.Models.State'. What I'm trying to do I need to pass the result of the following linq query to a View. using (var db = new migros_mockEntities1()) { var listOfIdeas = (from x in db.States select x.ID); return View(listOfIdeas); } The View requires IEnumerable

Possible to add migration using EF DbMigrator

[亡魂溺海] 提交于 2019-12-13 06:07:21
问题 Is it possible to add a migration file using DbMigrator in code instead of through the powershell commands? 回答1: DbMigrator is class for running migrations. Classes for creating migration are in System.Data.Entity.Migrations.Design. ToolingFacade is called by powershell commands. Other classes represents low level API for creating migration code. 来源: https://stackoverflow.com/questions/12353840/possible-to-add-migration-using-ef-dbmigrator

Force hint to index from entity framework to SQL Server

大憨熊 提交于 2019-12-13 05:41:39
问题 I am calling SQL Server 10 from Entity Framework in C# and want to get a query hint into the request. The database has indexes which operated normally from SQL run in Management Studio, but when calling the command from C# using Entity Framework in Visual Studio, the query planner chooses a full scan when there is already an index. I am creating dynamic predicates to request data in the following form: data.attributeText = data.vegaDB.attributeText.AsExpandable().Where(parentPredicate.Compile

MVC Code First Connection String. I changed it. How do I reinitialize the database?

断了今生、忘了曾经 提交于 2019-12-13 05:25:06
问题 I mean I was using a .SDF file but then had issues getting that to work with my host. So then I went back to the SQL DB I already have but I noticed that when I go to the default MVC 4 index page it is looking for that entity that I already created when I used the original DB.. but this table does not exist with the new SQL DB I switched to.. I already verified that is is pointing to the new DB buy setting the connection string in the constructer. How do I tell the code to 'RE CREATE THE