entity-framework-4

How to run an SQL script against a MDF file?

别来无恙 提交于 2020-01-03 09:25:14
问题 I've created a database model with model-first method using Entity Framework 4.0. I then created an sql script using the Generate Database from Model... I've also created an SQL Server Database file in my App_Data folder. How do I now run the SQL file against this MDF file? I'm using Visual Studio 2010. 回答1: I ran into this same problem and here is what worked for me. When I selected "Generate Database from Model..." I created a new MDF file. This process worked fine and Visual Studio

DbContext doesn't release SQLite database

倖福魔咒の 提交于 2020-01-03 08:48:08
问题 First, these are my intentions: Create a DbContext on SQLite Read and write from/to it Close context Move the file to another location Points 1-3 work perfectly. The problem starts when I try to move the database. I get an error stating that: 'The process cannot access the file because it is being used by another process.' How can I resolve this? First, I create a context. I have to use it in several methods, and I don't want to create it every time I need it. So I am storing it as a member.

Handling BLOBs in Entity Framework 4.0 in a stream-fashion

戏子无情 提交于 2020-01-03 08:45:21
问题 Is it possible to handle (read and write) binary data to SQL Server using Entity Framework 4.0 using streams? (i.e.: not the whole content shipped in a byte array) An example could be taken from Download and Upload images from SQL Server via ASP.Net MVC which illustrates the way to stream nicely data from SQL Server in an example available for ASP.NET MVC. However it requires direct access to the DB and I am curious whether this could be done using an ORM. 回答1: Unfortunately, this is not

EF4.0, repositories, and Ninject 2

蓝咒 提交于 2020-01-02 23:35:12
问题 This is in continuation of two ongoing problems I'm facing: Problems trying to attach a new EF4 entity to ObjectContext while its entity collection entities are already attached and EF4.0 - Is there a way to see what entities are attached to what ObjectContext during debugging? I'm using this space to ask another somewhat complicated question, and I don't want to make a huge, ultra long question out of my other threads. So, a quick rundown: I have incoming form data which is bound to a DTO. I

How to add or remove a many-to-many relationship in Entity Framework?

落爺英雄遲暮 提交于 2020-01-02 21:15:09
问题 There's a many-to-many UserFeed table that stands between User and Feed and denotes a twitter-like follow relationship. It only has two fields, which form a composite key: UserID and FeedID . I need to write a method that will subscribe or unsubscribe a user from a feed based on a boolean flag. public void SetSubscriptionFlag (int userId, int storeId, bool subscribe) { } I'm new to Entity Framework so I'm trying to find and follow an "EF-ish" way to accomplish this. My initial thoughts are:

How to add or remove a many-to-many relationship in Entity Framework?

匆匆过客 提交于 2020-01-02 21:14:51
问题 There's a many-to-many UserFeed table that stands between User and Feed and denotes a twitter-like follow relationship. It only has two fields, which form a composite key: UserID and FeedID . I need to write a method that will subscribe or unsubscribe a user from a feed based on a boolean flag. public void SetSubscriptionFlag (int userId, int storeId, bool subscribe) { } I'm new to Entity Framework so I'm trying to find and follow an "EF-ish" way to accomplish this. My initial thoughts are:

Changing entity name/poco class name from table name while creating model from the database

坚强是说给别人听的谎言 提交于 2020-01-02 17:15:55
问题 I want to create a entity model from the existing database but all the table names contain "_"/underscore in the database so while creating poco classes i want remove underscore from name of the entities/poco classes. Is there a way to change the naming convention while the entities are created in the entity framework during the creation of model from database Thanks, Amit 回答1: You have two options, There is a little bit of a learning curve but it involves using T4 templates to do the code

ASp.NET MVC EF4 SQL Table or Field level security

空扰寡人 提交于 2020-01-02 13:55:55
问题 I have an slightly unusual security requirement, and I'm looking for advice on best practice, or at-least non-brittle approaches. Scenario: Intranet system. Data about a number of related entities is to be considered as private. This is known as the unpublished part of the system. Only certain users can access this data. At some stage the users make a selection from this data, mark some records and publish them to the "published" side. The data published to the published side is removed from

How to append a where clause to an Entity Framework ObjectSet

自古美人都是妖i 提交于 2020-01-02 12:27:26
问题 I would like to append a set of conditional where clauses onto the end of an ObjectSet. However, the clauses do not get executed and instead the original query is run, for example: using (Entities context = new Entities()){ var q = context.AuditLogs; q.Where(o => o.WebsiteId == 1); } The where clause is not executed and the full result set is returned I could instead use IQueryAble as in: var q = context.AuditLogs.AsQueryable(); q = q.Where(o => o.WebsiteId == 1); However this loses me the

How to append a where clause to an Entity Framework ObjectSet

邮差的信 提交于 2020-01-02 12:27:06
问题 I would like to append a set of conditional where clauses onto the end of an ObjectSet. However, the clauses do not get executed and instead the original query is run, for example: using (Entities context = new Entities()){ var q = context.AuditLogs; q.Where(o => o.WebsiteId == 1); } The where clause is not executed and the full result set is returned I could instead use IQueryAble as in: var q = context.AuditLogs.AsQueryable(); q = q.Where(o => o.WebsiteId == 1); However this loses me the