datacontext

Should I return IEnumerable<T> or IQueryable<T> from my DAL?

梦想的初衷 提交于 2019-11-29 19:32:59
I know this could be opinion, but I'm looking for best practices. As I understand, IQueryable<T> implements IEnumerable<T> , so in my DAL, I currently have method signatures like the following: IEnumerable<Product> GetProducts(); IEnumerable<Product> GetProductsByCategory(int cateogoryId); Product GetProduct(int productId); Should I be using IQueryable<T> here? What are the pros and cons of either approach? Note that I am planning on using the Repository pattern so I will have a class like so: public class ProductRepository { DBDataContext db = new DBDataContext(<!-- connection string -->);

Inconsistent accessibility problem [duplicate]

孤人 提交于 2019-11-29 15:23:26
This question already has an answer here: Inconsistent accessibility error with the following c# code. Why? 3 answers I am following Rob Conery MVC Storefront tutorial series and I get an Inconsistent accessibility error from the following constructor public SqlCatalogRepository(DB dataContext) : public class SqlCatalogRepository : ICatalogRepository { DB db; public SqlCatalogRepository() { db = new DB(); //turn off change tracking db.ObjectTrackingEnabled = false; } public SqlCatalogRepository(DB dataContext) { //override the current context //with the one passed in db = dataContext; } Here

WPF Update Binding when Bound directly to DataContext w/ Converter

我只是一个虾纸丫 提交于 2019-11-29 14:48:00
问题 Normally when you want a databound control to 'update,' you use the "PropertyChanged" event to signal to the interface that the data has changed behind the scenes. For instance, you could have a textblock that is bound to the datacontext with a property "DisplayText" <TextBlock Text="{Binding Path=DisplayText}"/> From here, if the DataContext raises the PropertyChanged event with PropertyName "DisplayText," then this textblock's text should update (assuming you didn't change the Mode of the

Bind to parent DataContext within DataTemplate

筅森魡賤 提交于 2019-11-29 14:28:11
问题 I'm trying to bind MenuItem's Command to command contained in UserControl.DataContext . I've found couple of similar question, but solution according to them is failing to me: <UserControl ...> <UserControl.Resources> <DataTemplate x:Key="TileItemStye"> <Grid Width="100" Height="100"> <Grid.ContextMenu> <ContextMenu> <MenuItem Header="Remove" Command="{Binding DataContext.RemoveItem, RelativeSource={RelativeSource FindAncestor, AncestorType=UserControl}}"> </MenuItem> </ContextMenu> </Grid

How to get rid of StackOverflow Exception in DataContext InitializeComponent?

梦想与她 提交于 2019-11-29 12:23:30
I am new to wpf c#, trying some sample application, the problem is when I mention DataContext in xaml the InitializeComponent is called recursively and is showing System.StackOverflowException' occurred in mscorlib.dll This is my XAML markup: <Window x:Class="Company1.MainWindow" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:local="clr-namespace:Company1" Title="MainWindow" Height="350" Width="525" > <Window.DataContext> <local:MainWindow/> </Window.DataContext> <Grid> <GroupBox Margin="5,5,5,5" Background="Beige"

WPF Binding Syntax Question

你。 提交于 2019-11-29 11:23:26
I've seen this syntax show up, and have tried to google for it's definition to no avail; what does it mean when a dp is bound this way? <Grid> <ContentControl Content="{Binding}"/> </Grid> I was under the assumption that you have to bind to some property on the DataContext, or another element, but this appears to bind to nothing. I believe it means you are binding to the root of whatever the binding context is. So if you use this syntax in a datatemplate that is part of some sort of list control, you would be binding to the root level of whatever the parent control (the list control) was

How to configure mvc mini profiler with Linq to SQL?

江枫思渺然 提交于 2019-11-29 11:05:15
I have configured mini profiler with asp.net mvc application. I also want to profile my db so I hooked it with L2S datacontext as in this example . It is working fine for some queries but on other queries I find null reference exception. When I attached the source code to debug I found out that internal void AddSqlTiming(SqlTiming stats) { Head.AddSqlTiming(stats); } Head Property in above method is null in MiniProfiler.cs at line 198. Any idea why? EDIT: Following method returns me the datacontext object public static EvoletDataContext Get() { var connection = ProfiledDbConnection.Get(new

How to hide a control if the underlying DataContext is null?

帅比萌擦擦* 提交于 2019-11-29 10:59:05
问题 I have an object in my view model that has a bunch of properties, some of them will occasionally be null. I don't want to just show some controls if these particular controls are null. How would I go about hiding the control if the bind is null? I was thinking of some sort of converter, but don't know how I'd go about doing it exactly. Any ideas? edit: sorry, I should mention that this will also be in Silverlight, so I'm not sure if Style triggers would work...? 回答1: Have a converter like

Linq: Get a list of all tables within DataContext

人盡茶涼 提交于 2019-11-29 09:33:31
问题 I have a DataContext (Linq to Sql) with over 100 tables, is it possible to get a list of all those tables and lets say print them to the console? This might be a silly question. Thanks. 回答1: It's much easier than above and no reflection required. Linq to SQL has a Mapping property that you can use to get an enumeration of all the tables. context.Mapping.GetTables(); 回答2: You can do this via reflection. Essentially, you iterate over the properties in your DataContext class. For each property,

Are Multiple DataContext classes ever appropriate?

让人想犯罪 __ 提交于 2019-11-29 05:26:04
In order to fully use LinqToSql in an ASP.net 3.5 application, it is necessary to create DataContext classes (which is usually done using the designer in VS 2008). From the UI perspective, the DataContext is a design of the sections of your database that you would like to expose to through LinqToSql and is integral in setting up the ORM features of LinqToSql. My question is: I am setting up a project that uses a large database where all tables are interconnected in some way through Foreign Keys. My first inclination is to make one huge DataContext class that models the entire database. That