entity-framework-4

View EF4 generated queries?

爱⌒轻易说出口 提交于 2019-12-23 00:49:12
问题 LINQ-to-SQL had several ways, including a visualizer add-in, to view the generated SQL from an IQueryable. I can't find the equivalent for Entity Framework 4. Nothing on StackOverflow, no blogs. How is it done? Preferably, I'd like to be able to do it in code and without having to actually execute the query just to see it. Thanks! 回答1: there are several approaches to looking at the sql. Free On the ObjectQuery do .ToTraceString() that will show u the sql generated for the query. Download ef

Why are these asynchronous RIA Service calls executed in serial on the web server?

别来无恙 提交于 2019-12-22 19:37:31
问题 I'm calling the RIA Service method ImportSubcomponentFileSetFiles (which is an Invoke, not Query) twice as follows: foreach (var viewModel in FileSetViewModels.Where(vm => vm.IsSelectedForImport)) { DomainContext.ImportSubcomponentFileSetFiles(viewModel.SubcomponentFileSet.Id, callback => { //... DomainContext.Load(DomainContext.GetSubcomponentFileSetWithStatusQuery(subcomponentFileSetId), LoadBehavior.RefreshCurrent, callback2 => { //... }, true); }, null); } I can see in Fiddler that two

Why are these asynchronous RIA Service calls executed in serial on the web server?

半城伤御伤魂 提交于 2019-12-22 19:37:05
问题 I'm calling the RIA Service method ImportSubcomponentFileSetFiles (which is an Invoke, not Query) twice as follows: foreach (var viewModel in FileSetViewModels.Where(vm => vm.IsSelectedForImport)) { DomainContext.ImportSubcomponentFileSetFiles(viewModel.SubcomponentFileSet.Id, callback => { //... DomainContext.Load(DomainContext.GetSubcomponentFileSetWithStatusQuery(subcomponentFileSetId), LoadBehavior.RefreshCurrent, callback2 => { //... }, true); }, null); } I can see in Fiddler that two

how to avoid SQL Injection with Linq with EF in codefirst technique in c#

情到浓时终转凉″ 提交于 2019-12-22 19:25:33
问题 I am using asp.net mvc 3 with WCF with EF 4.1 With Sql Azure. I am building the search engine for my application. and using the dynamic Linq to build queries. I want to avoid the sql injetion in this scenario. what is the best practice for the same ? what are the precaoution i should take in this scenario ? 回答1: As long as your are building your queries through LINQ, then you are not vulnerable to SQL injection. While this doesn't mean that your code is invulnerable to ALL sorts of attacks

Entity Framework 4 SaveChanges not working and not throwing any error?

冷暖自知 提交于 2019-12-22 18:44:29
问题 I am trying to use my generic repository with a "unit of work" pattern. Here is my work details public class GenericRepository:IRepository { private readonly string _connectionStringName; private ObjectContext _objectContext; private readonly PluralizationService _pluralizer = PluralizationService.CreateService(CultureInfo.GetCultureInfo("en")); public GenericRepository() { this._objectContext = ContextManager.CurrentFor(); } public void Add<TEntity>(TEntity entity) where TEntity : class { (

unable to return json data, WCF Resful Service .NET 4.0

被刻印的时光 ゝ 提交于 2019-12-22 18:37:00
问题 I recently set up a WCF Resful Service with Entity Framework 4.0 It works with XML perfectly, however when I try to return it in json format I got HTTP/1.1 504 Fiddler - Receive Failure Content-Type: text/html Connection: close Timestamp: 01:11:06.453 ReadResponse() failed: The server did not return a response for this request. Any Ideas?? thanks in advance Edit: The Code is quite normal, actually i tried two way of doing it, but no luck. Hard code ResponseFormat Way: [OperationContract]

How to handle an association table linking the same 2 tables

蹲街弑〆低调 提交于 2019-12-22 18:12:55
问题 I am using Entity Framework 4.3 code first using an already existing database. There is a Users table that has the following columns: - UserID (int) - FirstName (string) - Surname (string) I have an association table called Impersonations . The Impersonations table is an association table between a user table and the same user table. A user can have a list of users. Here is the Impersonations table structure: - ImpersonateID (int primary key) - UserID (int FK to Users table's UserID column) -

How to extend Entity from EF?

孤街浪徒 提交于 2019-12-22 12:37:35
问题 All entity created by EF is partial class. so it is extendable. Suppose I have entity Person like partial class Person{FirstName, LastName, .....} Then I want to add a compute property Name like: partial class Person{ [DataMember] public string Name { get { return String.Format("{0} {1}", this.FirstName, this.LastName); } } partial void OnFirstNameChanged() { //..... this.ReportPropertyChanged("Name"); } partial void OnLastNameChanged() { //..... this.ReportPropertyChanged("Name"); } //.... }

Automating ConcurrencyMode set to Fix in EDMX

此生再无相见时 提交于 2019-12-22 11:33:50
问题 Majority of our tables in our models has a field called "intConcurrencyID" that we intended to use for concurrency checking. I believe the only way to enable this field for concurrency checking in a Database First environment is to set the Concurrency Mode to Fixed. However, if we have huge numbers of tables per EDMX, we will have a hard time manually configuring each type per entity not to mention the possibility of some entities to be overlooked. Do you have any ideas on how I can automate

Building dynamic where clause, Linq To Sql

泄露秘密 提交于 2019-12-22 11:17:18
问题 I am using EF Code first 4.2, What sort of solution do you propose when the where clause needs to be dynamically built? Yet Include functionality would be highly required: var results = db.Set<dynamicType>.Where("dynamic conditions").Include("...."); The dynamic condition above needs to lookup to another table to filter the records: If I wanted to write that in Linq expression it would be something like: var result = db.Set<Contact>().Where(c=>c.AccountId == _Id_param || db.Set<LinkTable>()