entity-framework-4

What are best practices for managing DataContext?

﹥>﹥吖頭↗ 提交于 2019-12-10 12:15:36
问题 In an effort to make my entities persistent ignorant and make my repositories testable, I've implemented a repository pattern like so: public interface IJobRepository : IRepository<Job> { Job GetJobById(int jobId); //Special case where I'm eager loading other entities void SaveJob(Job job, Job originalJob); } public class JobRepository : IJobRepository { private readonly IContext _context; public JobRepository() { _context = new CustomObjectContext(); } public JobRepository(UnitOfWork

Entity Framework - Getting the length of data in a text column

你说的曾经没有我的故事 提交于 2019-12-10 11:55:27
问题 I've hit an error when I've been working on a table that uses a text field. If I was getting the length of a varchar column I could do var result = (from t in context.tablename select t.fullname.Length) However, if I run the same query on a text field: var result = (from t in context.tablename select t.biography.Length) I get the error : Argument data type text is invalid for argument 1 of len function . Having done a bit of reading up on the subject I understand why SQL Server raises this

Purpose of edmgen validation? Comparing SSDL and database schemas?

血红的双手。 提交于 2019-12-10 11:45:51
问题 Not sure what the EDMGEN is validating here It validates the ssdl file against a live database schema looking for inconsistencies)? Ot it only validates the internal consistency between the ssdl, csdl and msl files? If nobody has changed manually the contents of the autogenerated ssdl, csdl and msl files is there any reason to validate them? Is this validation the same that runs when "Validate On Build" property of the ConceptualEntityModel is set to true in visual studio? Is there any way to

EF code first List<DateTime> not creating table

核能气质少年 提交于 2019-12-10 11:44:35
问题 I am creating a very simple EF4 code first project with one entity. public class Activity { public Guid Id { get; set; } public string Description { get; set; } public List<DateTime> DateDone { get; set; } <snip> public Activity() { if(DateDone==null) DateDone = new List<DateTime>(); } } I rebuild my project and then run the MVC3 app and the database generates (confirmed, I have added and removed columns), my data is seeded (it changes on screen when I modify the seeded data) I am able to:

Setting up .NET MVC3 with MySQL

为君一笑 提交于 2019-12-10 11:18:37
问题 Hy Guys, How can I configure the webconfig to access a mysql db using MVC 3? To use SQLExpress I included this code to configure in an example... <add name="MovieDBContext" connectionString="Server=.\SQLEXPRESS; Database=Movies;Trusted_Connection=true" providerName="System.Data.SqlClient" /> I'm using Entity Framework. PS.: I don't want to automatically create tables with the MVC. I want to create them manually. Thks! 回答1: Take a look at this post, it seems like your best option is to use

EntityFramework : Calling ToList() on IQueryable with ~11.000 records takes 10 seconds

浪尽此生 提交于 2019-12-10 10:57:03
问题 I want to return a relatively large number of records from SQL Express 2008 R2 server, via EntityFramework 4 through WCF service to a WCF client. My test table contains around 11.000 records at the moment. The LINQ query is as simple as this: Database DB = new Database(); // create object context var retValue = DB.Entities.Persons .Include("District") .Include("District.City") .Include("District.City.State") .Include("Nationality") return retValue.ToList(); This takes about 10 seconds to

Entity Framework 4 CTP 4 Code First: how to work with unconventional primary and foreign key names

孤人 提交于 2019-12-10 10:56:25
问题 Is there a way in Entity Framework 4 (using CTP4 and Code First if that matters) to change the conventions used to automatically identify primary and foreign keys? I'm trying to use EF with a legacy database that uses a "pk/fk" prefix rather than an "id" suffix to mark keys. Also, it's not uncommon to have multiple foreign keys to an Address table, for example, called "fkAddressHome" and "fkAddressWork". I would prefer a method for changing this behavior in a systematic way so that I don't

Entity Framework get user from contex in saveChanges

…衆ロ難τιáo~ 提交于 2019-12-10 10:42:55
问题 i have two projects in my solution, UI as mvc and class project for entitiy model code first. I have severall entities in my model but now I need to extend them by new audit fields where I need to save who changed entity. I added new interface public interface IAuditable { /// <summary>Gets or sets the name.</summary> /// <value>The name.</value> DateTime CreatedDate { get; set; } /// <summary>Gets or sets the name.</summary> /// <value>The name.</value> string CreatedBy { get; set; } ///

EF4 how to call a scalar UDF

主宰稳场 提交于 2019-12-10 10:30:15
问题 I am trying to call a scalar UDF in SQL Server from the entity framework. It shows up in the the model browser in the Store section. Any help is Appreciated.. //In the EDMX File it shows up in the storage model <Function Name="GetPerformanceIndicator" ReturnType="float" Aggregate="false" BuiltIn="false" NiladicFunction="false" IsComposable="true" ParameterTypeSemantics="AllowImplicitConversion" Schema="dbo"> <Parameter Name="inv" Type="int" Mode="In" /> <Parameter Name="fund" Type="int" Mode=

Does Entity Framework(EF5) support XML data type yet?

ぐ巨炮叔叔 提交于 2019-12-10 10:28:20
问题 I am thinking of using the XML data type in SQL Server 2008 R2, but also using EF with MVC. Does EF5 support the XML data type? If not then I will have to opt for a different DB design. Many thanks. 回答1: EF does not support Xml type natively at the moment 来源: https://stackoverflow.com/questions/13031041/does-entity-frameworkef5-support-xml-data-type-yet