entity-framework-4

Pre-Generate Views for EF Code First

隐身守侯 提交于 2019-12-10 10:15:42
问题 Having finally deployed to live a new site built with Entity Framework Code First and MySql, one nagging annoyance is the pause often experienced while view metadata is cached. This seems to happen far more frequently than the application pool is recycled. (?) I guess that for a site which has a constant stream of traffic this might not be noticed often. For a new site with infrequent traffic it feels like every time I go to the site there's a 4-5 second delay in rendering the first page. So

entity framework and where with like [duplicate]

假如想象 提交于 2019-12-10 10:13:31
问题 This question already has answers here : Like Operator in Entity Framework? (10 answers) Closed 8 months ago . I' m using this instruction: db_user = db.CBR_User.FirstOrDefault(p => p.Codice_Fiscale == code); I want use "like" operator instead == for manage case insensitive How can do it? thanks 回答1: If you want to do an equality comparison anyway, I suggest two ways: db_user = db.CBR_User.FirstOrDefault(p => p.Codice_Fiscale.Equals(code, StringComparison.OrdinalIgnoreCase)); Or db_user = db

Entity framework work locally but not on azure

巧了我就是萌 提交于 2019-12-10 08:50:31
问题 I have a web project which works perfectly locally. But when I change the connection string in my published web site on Azure to connect to my database on SQL Azure it will start giving this error. System.Data.Entity.Infrastructure.UnintentionalCodeFirstException: Code generated using the T4 templates for Database First and Model First development may not work correctly if used in Code First mode. To continue using Database First or Model First ensure that the Entity Framework connection

Entity Framework 4.0: Entity SQL CAST Operation Not Working

≯℡__Kan透↙ 提交于 2019-12-10 07:27:18
问题 I'm trying to make a query where I cast a text column, which contains an integer as text, to an Int32. Here's the query: SELECT VALUE t FROM MyEntities AS t WHERE CAST(t.TextColumn AS Edm.Int32) > 5 However, I get an System.Data.EntitySqlException with the following message: Type 'Edm.Int32' could not be found. Make sure that the required schemas are loaded and that the namespaces are imported correctly. Near type name, line 1, column 75. According to MSDN, Edm.Int32 should be a valid type.

Simplest Way to Delete Object with Entity Framework 4

梦想与她 提交于 2019-12-10 06:41:05
问题 Ack! I'm new to Entity Framework and am trying to find the simplest way to delete an item. I have a listbox with the datasource set to TagCategory objects from the database. This is working fine. Now I'd like to delete the selected item. So I do something like this: TagCategory category = (TagCategory)lstCategories.SelectedItem; using (MyEntities context = new MyEntities()) { context.AttachTo("TagCategories", category); context.DeleteObject(category); context.SaveChanges(); } This seems

Why is the TableAttribute in the Entity Framework Dll?

坚强是说给别人听的谎言 提交于 2019-12-10 06:37:22
问题 Is there a good reason why the Table attribute (which can be used to map a POCO class to the correct database name/schema) is in the EntityFramework.dll? Doesn't this prevent you from creating a Domain project that simply contains your entities with no dependency on a specific data access technology? For example, if I use this attribute I don't believe the classes would be portable to Silverlight. Is this an oversight, or am I missing something? I realize I could use the fluent API to

LINQ Query Issue, Sequence contains no elements

元气小坏坏 提交于 2019-12-10 03:39:43
问题 I'm trying to update a single record in a table, but when I run .Firstordefault() , I get the error: "Object reference not set to an instance of an object.", and if use it with .First() , I get "Sequence contains no elements". Using it another place, its working fine, but this time its causing errors. Here's the code: public class AllownceDetails { public int ta_id{get;set;} public int tvrid{get;set;} public DateTime ofDate{get;set;} public string status{get;set;} public string userid {get

The method 'Skip' is only supported for sorted input in LINQ to Entities. The method 'OrderBy' must be called before the method 'Skip'

烂漫一生 提交于 2019-12-10 02:48:54
问题 I am working on a Dynamic data. after creating a dynamic model and registering in global.asax, like DefaultModel.RegisterContext(typeof(masterEntities1),new ContextConfiguration() { ScaffoldAllTables = true }); when i run an application, it shows a list of tables but when i click any of the table it throws an exception: The method 'Skip' is only supported for sorted input in LINQ to Entities. The method 'OrderBy' must be called before the method 'Skip'. but i haven't declare any query into my

The 'DbProviderFactories' section can only appear once per config file

两盒软妹~` 提交于 2019-12-10 02:30:56
问题 We are receiving this error when calling a WCF .net 4.0 service using entity framework. The 'DbProviderFactories' section can only appear once per config file It is the first app on the server using EF and other .net 4.0 WCF services are not receiving this error. Is there any way to correct this error with out editing the machine config file on the server? 回答1: Maybe you could create web.config entries which override any machine-wide settings you want changed. Described here: Override machine

entity type has no key defined - Code first

放肆的年华 提交于 2019-12-10 02:08:15
问题 I'm new to MVC as well as the entity framework. I searched lot and find few similar questions (e.g. Entity Type Has No Key Defined) but they don't solve my problem. namespace MvcAppInvoice.Models { public class Customer { public int CustomerID { get; set; } public string FirstName { get; set; } public string SurName { get; set; } public virtual CustomerType Type { get; set; } } public class CustomerType { public int TypeId { get; set; } public string TypeName { get; set; } public virtual