entity-framework-4

Correct way to pass Entity objects between layers?

断了今生、忘了曾经 提交于 2019-12-05 20:56:23
I am just learning the Entity Framework and have made some good progress on incorporating it with my layered code structure. I have 2 visual layers, a business layer and a data access layer. My problem is in passing entity object between layers. This code sample does not work: // BLL public static void Test1() { List<User> users = (from u in GetActiveUsers() where u.ID == 1 select u).ToList<User>(); // Do something with users } // DAL public static IQueryable<User> GetActiveUsers() { using (var context = new CSEntities()) { return from u in context.Users where u.Employee.FirstName == "Tom"

Testing : How to create fake object context using TypeMock for EF4 model

会有一股神秘感。 提交于 2019-12-05 20:55:41
I am using EF4 in my application and I want to make test cases for DAL methods, which generally hit the database to get data. I am using the Typemock framework for Mocking. I want to mock database call and only want to test queries. E.g.: ObjectContext.Where(u => u.code == Code) For doing this, I need to make Fake ObjectContext for EF Models and want to fill some fake data in Fake ObjectContext so that we can execute our queries (LINQ) on fake ObjectContext . Kindly suggest how can I can create fake object context(Using TypeMock framework) and fill data in the entities. For example, I have the

Why are my EF Code First pregenerated views having no effect?

ⅰ亾dé卋堺 提交于 2019-12-05 20:33:26
问题 I have ~300 DbSets in my context and the first query after app load (a FirstOrDefault() where on an indexed field) takes ~40 seconds. To improve this, I am attempting to use pregenerated views in EF 4.3.1 Code First using the T4 template here: http://blog.3d-logic.com/2012/06/13/entity-framework-codefirst-view-generation-templates-on-visual-studio-code-gallery/ I compile it in, but I see no performance difference. I was hoping/assuming it would help the painful slow startup I am experiencing,

entity framework and where with like [duplicate]

十年热恋 提交于 2019-12-05 20:02:45
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 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.CBR_User.FirstOrDefault(p => p.Codice_Fiscale.ToUpper() == code.ToUpper()); If you don't want that, you can

How to get rid of 'property could not be set to a double value, you must set this property to a non-null value of type decimal'

南笙酒味 提交于 2019-12-05 19:22:40
I'm trying to get a function import to work correctly. EF calls out to my stored procedure, but the result has an inner exception that I don't understand: var result = context.SomeFunctionImport(); I get: The 'Cnt' property on 'SomeClass' could not be set to a 'Double' value. You must set this property to a non-null value of type 'Decimal'. Here's the Cnt property on SomeClass : [DataMember] public Nullable<decimal> Cnt { get { return _cnt; } set { if (_cnt != value) { OnComplexPropertyChanging(); _cnt = value; OnPropertyChanged("Cnt"); } } } private Nullable<decimal> _cnt; You need to define

EF4: Get the linked column names from NavigationProperty of an EDMX

久未见 提交于 2019-12-05 19:11:50
问题 I am generating POCOs (lets say they are subclasses of MyEntityObject ) by using a T4 template from an EDMX file. I have 3 entities, e.g.: MyTable1 (PrimaryKey: MyTable1ID) MyTable2 (PrimaryKey: MyTable2ID) MyTable3 (PrimaryKey: MyTable3ID) These entities have the following relations: MyTable1.MyTable1ID <=> MyTable2.MyTable1ID (MyTable1ID is the foreign key to MyTable1) MyTable2.MyTable2ID <=> MyTable3.MyTable2ID (MyTable2ID is the foreign key to MyTable2) Or in another view: MyTable1 <=

Return Entity Framework objects from WCF

大城市里の小女人 提交于 2019-12-05 19:02:27
I am working on a WCF service to provide data to multiple mobile clients. Data model is Entity Framework 4.0. Schema is given below. When i returnt he object of SysUser the result also contains the navigation properties and EntityKey and other EF related stuff. Is it possible that i get the pure object(only the database fields without the relationship etc). Thanks Update the exception occures "Only parameterless constructors and initializers are supported in LINQ to Entities." on followign code: return (from u in DataSource.SysUsers where u.UserID == UserID select new Player(u) )

Entity Framework with MYSql, return no column in complex entity return type

大兔子大兔子 提交于 2019-12-05 18:47:22
I'm using MySQL in combination with an edmx file. I'm facing a problem when adding a function to stored procedure. When I select "complex type" and press the "get column information" button I receive the following message: "The selected stored procedure returns no columns." When I create the same procedure in SQL Server and then added the function to a new edmx file, its creating the complex type perfectly. Thanks, Nauman 来源: https://stackoverflow.com/questions/9940749/entity-framework-with-mysql-return-no-column-in-complex-entity-return-type

Update non-scalar entities in Entity Framework v4

六眼飞鱼酱① 提交于 2019-12-05 18:40:56
Currently I am updating the scalar properties of the candidate object like so: public Candidate EditCandidate(Candidate candidateToEdit) { _entities.Candidates.Attach(new Candidate { ID = candidateToEdit.ID }); _entities.Candidates.ApplyCurrentValues(candidateToEdit); //update candidate.contact here somehow _entities.SaveChanges(); return candidateToEdit; } This only updates the Candidate scalars, since that's what ApplyCurrentValues does. I also need to update the candidate.contact object as well, currently it seems like the only option is to get the current candidate in the database via the

EF4: how to use a generic repository pattern ?

99封情书 提交于 2019-12-05 18:39:10
I'm trying to streamline my existing repos by using a generic repo I can subclass from. The problem is that I can't figure out how to write a few of my base class methods. I currently have: public interface IRepository<T> : IDisposable where T : class { IQueryable<T> GetAll(); T GetSingle(int id); T GetSingle(string slug); void Save(T entity); } public class HGRepository<T> : IRepository<T> where T : class { protected HGEntities _siteDB; protected IObjectSet<T> _objectSet; public HGRepository(HGEntities context) { _siteDB = context; _objectSet = _siteDB.CreateObjectSet<T>(); } public