linq-to-entities

How to load varbinary(max) fields only when necessary with ADO.NET Entity Framework?

老子叫甜甜 提交于 2020-01-03 08:14:09
问题 I have a varbinary(max) field in one of my tables but I don't need it every time and I'm looking for a way to fetch it from the database only when necessary. I'm using ADO.NET Entity Framework. How to do that? 回答1: The solution was to create a separate table with the varbinary field and make 1-to-1 relationship between the tables 回答2: It is not necessarily to create separate table. You should do several steps. Let's assume that we have table 'Documents' (Id, Name, Data (varbinary)). Open EF

Delete entities without loading them into memory

不问归期 提交于 2020-01-03 07:12:12
问题 In Entity Framework Core I have the following Entity: public class File { public Int32 Id { get; set; } public Byte[] Content { get; set; } public String Name { get; set; } } And I have a list of files ids which I need to delete: List<Int32> ids = new List<Int32> { 4, 6, 8 }; // Ids example How can I delete the 3 files without loading each file Content property? _context.Files.Remove(??); I do not want to load each file Content property as it is big in size. 回答1: If you are sure the all Ids

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:

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

Linq to Sql vs Nhibernate vs SubSonic vs Stored Procedure (Help)

那年仲夏 提交于 2020-01-02 11:02:12
问题 I am looking to develop a website for a news channel . So, Obviously its gonna receive a lot of hits daily and will be updated a lot on daily basis.. I have experience in ASP.Net and SQL Server.. These are the technologies i am considering to work with. Please help me choose the right method considering the amount of load it will take.. Technology?? 1) ASP.Net Webforms 2) ASP.Net MVC 1.0 And data access?? 1) Linq to SQL (Impressive but rumours say Microsoft is abandoning it) 2) Linq to

Converting 2 argument Lambda expression to 1 argument Lambda expression (specifying one argument)

夙愿已清 提交于 2020-01-02 06:08:54
问题 I have expression Expression<Func<Car, Driver, bool>> CanBeDrivenBy = (car, driver) => car.Category == 'B' && driver.Age > 18; and I want to get cars which can be driven by some driver IQueryable<Cars> cars = ...; Driver driver = ...; cars.Where(CanBeDrivenBy); // Fail, expecting Expression<Func<Car, bool>> So I need to convert Expression<Func<Car, Driver, bool>> to Expression<Func<Car, bool>> (specify driver) Yes I can use cars.Where(c => c.Category == 'B' && driver.Age > 18); but I need

Include derived property into a linq to entity query

拜拜、爱过 提交于 2020-01-02 05:56:19
问题 Here is a simple project based on a Poco class named Task : class Program { static void Main(string[] args) { using (MyDbContext ctx = new MyDbContext()) { // first query DateTime compareDate = DateTime.Now + TimeSpan.FromDays(3); var res = ctx.Tasks.Where(t => t.LastUpdate < compareDate).ToList(); // second query res = ctx.Tasks.Where(t => t.ShouldUpdate).ToList(); } } } public class MyDbContext : DbContext { public DbSet<Task> Tasks { get; set; } } public class Task { public int ID { get;

Select clause containing non-EF method calls

依然范特西╮ 提交于 2020-01-02 04:35:09
问题 I'm having trouble building an Entity Framework LINQ query whose select clause contains method calls to non-EF objects. The code below is part of an app used to transform data from one DBMS into a different schema on another DBMS. In the code below, Role is my custom class unrelated to the DBMS, and the other classes are all generated by Entity Framework from my DB schema: // set up ObjectContext's for Old and new DB schemas var New = new NewModel.NewEntities(); var Old = new OldModel