linqdatasource

Updating LinqDataSource from separate DataContext

老子叫甜甜 提交于 2020-01-25 03:55:08
问题 I want to update one LinqDataSource with a record retrieved from a different DataContext. The problem is that the DataContext of the LinqDataSource doesn't seem to be made public so I can't get access to it to attach the new object to the DataSource's context. What is the normal way of doing this? Or should I just scrap the LinqDataSource 回答1: Good reason for that - you can't share objects across different DataContexts. If you use the LinqDataSource's OnContextCreating event you can attach

How do I use EntityDatasource (Or LinqDatasource) with a Union clause

戏子无情 提交于 2020-01-17 08:03:11
问题 How do I combine records from two tables in an Entitydatasource control? I have googled it and searched on SO with no luck. The SQL of what I need is SELECT DISTINCT username FROM (SELECT s.username FROM project_stakeholders s UNION SELECT t.username FROM project_team_members t) My entities structure is as follows: project_stakeholders ---------------------- project_stakeholders.record_id (PK) project_stakeholders.username project_stakeholders.project project_stakeholders.project_id (FK)

Can you prevent LinqDataSource from setting a property?

空扰寡人 提交于 2019-12-24 06:23:05
问题 I've got a Linq 2 SQL object I'm trying to update. Two of the properties on this object are related to each other, and setting one sets the other. So if I do: Foo.Code = BEER; The Foo.CodeID property will automatically be set to 5 (or whatever.) The problem is that LinqDataSource sets Foo.Code, then immediately sets Foo.CodeID... which is not bound to anything since we want the users to set just Code. This immediately sets them both back to null. I know I can use Parameters to default values,

LINQDataSource - Query Multiple Tables?

别来无恙 提交于 2019-12-20 02:01:10
问题 I have a database and I've created a DBML Linq-to-SQL file to represent this database. I've created a new aspx page and dropped a linqdatasource and a formview control onto it. When I configure the linqdatasource it gives me the choice only to select * from one table...but I want to pull from multiple tables. e.g. I have tables like simple_person, simple_address, simple_phone, and I want to pull from all of them. How can I accomplish this? 回答1: Use a custom query http://weblogs.asp.net

Can I get EnableUpdate and EnableDelete to work on an EF4 LinqDataSource?

浪尽此生 提交于 2019-12-12 05:44:42
问题 So I started using Linq-To-Sql about 2 years ago, but my company is pushing me to switch to Entity Framework v4. Don't want to get into the L2s vs EF arguments here, please just assume that I cannot switch back to L2S. Anyway, in good ol' L2S, I'd define a gridview or listview, then a LinqdataSource with EnableUpdate=true, EnableDelete=true and EnableInsert=true. I'd assign the DataSourceID of teh gridview or listview to the ID of the linqdatasource and BAM! Instant CRUD. With EF4 however, it

LinqDataSource Where Parameter

我与影子孤独终老i 提交于 2019-12-12 02:05:35
问题 I have the below query on my aspx page that works: <asp:LinqDataSource ID="LinqDataSource1" runat="server" ContextTypeName="InventoryDataContext" EntityTypeName="" TableName="V_InventoryForDisplays" Where="ConfiguredCarId == @ConfiguredCarId"> <WhereParameters> <asp:Parameter DefaultValue="2827" Name="ConfiguredCarId" Type="Int32" /> </WhereParameters> </asp:LinqDataSource> I need to change the Where clause to use a Contains statement. I have an auto-propertyЖ public IEnumerable<int>

Binding LinqDataSource from code-behind to Gridview

假如想象 提交于 2019-12-11 06:26:55
问题 i have a grdidview control on the .aspx page and i am trying to connect dynamically from code behind and bind the gridview but somehow it throwing me an error... what is wrong with this code? any help? LinqDataSource LDS_POReport = new LinqDataSource(); LDS_POReport.ContextTypeName = "DataContextDataContext"; LDS_POReport.Selecting += new EventHandler<LinqDataSourceSelectEventArgs>(LinqDataSourcePO_Selecting); this.gvReport.DataSource = "LDS_POReport"; //this.gvReport.DataBind(); Update:

Linq to SQL data source best practice

前提是你 提交于 2019-12-11 06:14:21
问题 When using linq to SQL in my project I am currently creating the data context as late as possible in the code execution and disposing it as soon as possible. This results in the data context being open and closed many times on a page. Another option is to open the data class on page load and dispose it on page unload so the connection is only opened and closed once. Is there a significant difference in the optimization between the two methods or does one represent a best practice? My original

How can I prevent the LinqDataSource Where clause from resetting on postback?

拈花ヽ惹草 提交于 2019-12-07 14:47:46
问题 I'm trying to set the where clause on a LinqDataSource object bound to a GridView programmatically on a button click, but when the GridView rebinds data (for instance, when the user sorts) the Where clause resets back to the empty string. Is there a way to prevent this, or is there a better way to filter my results? 回答1: Perhaps you just add a ViewState property into your page/user control and then retrieve it on all post back? public string MyLinqSourceWhere { get { return (string)this

LinqDataSource does not support the Select property when the Delete, Insert or Update operations are enabled

徘徊边缘 提交于 2019-12-07 02:54:57
问题 I am getting this error when clicking the Delete button / link in a GridView control. LinqDataSource [DataSource] does not support the Select property when the Delete, Insert or Update operations are enabled I don't really understand why I'm getting this error because I have already done the same thing on a different webpage in my site, however the table that the data is read from in that case does not have any foreign keys, this one does. Is that why I am getting the error? If it matters,