ADO.NET :: How To Use Linq In Class File
Mar 2, 2011I have a businessprojects.cs in this project i am using linqtosql.dbml ... i am not able to create an instance for the linq
how to do this...
I have a businessprojects.cs in this project i am using linqtosql.dbml ... i am not able to create an instance for the linq
how to do this...
i have code in .cs class file
i need it in .vb
i used conversion tool for converting
but i feel its not proper as i am not able to reference it in my page
is there any other way
I have build a UserControl with separate code behind file.In that code behind file i have defined some public properties in the Partial class of user control that was automatically generated.Those properties will initialize some properties of controls that are used in the control.Now, in .aspx page i used this User Control and initialized the public properties through code behind of aspx page for dynamic contents.
View 6 RepliesI have below class and function. Could I use LINQ to select from class list?? What the syntax should be??
class ItemsPromo
{
public long itemID;
public long promotionID;[code]....
i want create a class Library work with SQL Linq ,when i create a LINQ Data Class it automatic create some connectionString and use the database namemy question is can i change some settings that, use this class Library in difrent website with difrent connectionStrings?
View 6 Repliesi have my page who load my gridview as: GRW.datasource=className.List2(2);i have this function in my class
[Code]....
it returns an error , cannot convert single result to queryable!! in " blo= DB.MarketList(TypeID);"
[code]....
I am going to return an Object depending on the Class and Year params. I want to remove the where condition when the Class and Year parames are null or zero.
i use GUI tool of vs2008 to generate some LINQ to SQL class, my problem is StringTemplate can not reach attributes of those model
$persons:{
<li>$it.name$</li>
}$
it printed:
<li></li>
<li></li>
<li></li>
name is public property of Person model. If i create a person class by myself, and the same attributes, StringTemplate can get it.
I have a class object which is basically kind of hierarchy and looks like this when I convert that to XML.
[Code]....
So you can see that I have "objectComponent" which is kind of hierarchy and that hierarchy can be upto any level.
Now I need to update <quantity> value where <sku> = "SKU 2", remember this <sku> can be anywhere in hierarchy, so I need to update its <quantity> value where <sku> = "SKU 2".
So my question is how can I update that value using Linq query and specifically, I need that value to be updated in the actual object itself because I need to pass that updated object for furthur process.
In my c# code, there is only one class named "ObjectComponent" and that has all of these properties and "objectBundle" as array and the whole hierarchy starts from there.
how can I update value in this object directly?
I want to write the Customer belongs their product
Customer 1 and their details
then products details Purchased by Customer 1
Customer 2 and their details
then products details Purchased by Customer 2
public class Customer {
public int CustID { get; set; }
public string CustName { get; set; }
public string CustEmail { get; set; }
public string CustContact { get; set; }
public string CustAdd { get; set; }
[Code] .....
I tried to add a custom property to the data model:
public partial class Department
{
public string ExtensionIdName
{
get
{
return Extension.ExtensionName;
}
set
{
}
}
}
It seems that it works, but when I bind the data to a ListView it shows all the properties except the property I added manualy (ExtensionIdName).
For some unknown reason I suddenly am unable to create an object variable for a Linq Data Class. If I create a new project and try the process again with the same database everything works as advertized.The code I am using is Dim db As New RoggDataContext which gives me an error on the object variable "db": Overload resolution failed because no accessibility 'NEW' accepts this number of arguments.I have looked inside every file in the Web Project like the web config to check the connection string, gobal, and designer.vb looking for any errors whit no JOY. I also tried to create a new form and code behind with a button and received the same error.This is mind blowing because as I already stated, I can create a new Web Site and the problem goes away.
View 3 RepliesI am creating a ASP.Net application in MVC architecture. I have to connect to a database on MS Access and be able to enter data into it. All examples I see use SQL Server. When I try from prject explorer Add New Item -> Data -> I am unable to find Drivers for Access Database.
From the Data Connections in Server Explrere window I was able to make a successful connection to the database.
Does MVC 2 support MS Access Database?
I am new to LINQ but not >net. I do understand SQLDataSource, etc. I was just told by a coworker not to use a LINQ to SQL Class for my new project (Bank.dbml). I was told to use instead the ADO.Net Entity Data Model (bank.edmx).
BankModel.edmxBank.dbml
When only using ADO.Net Entity Data Model I try to associate a GridView with a new LinqDataSource I get no options. When I add a LINQ to SQL Class I get the option to use it but it is empty. Is this because all my LINQ classes are mapped in the ADO.Net Entity Data Model (bank.edmx)? Can someone tell me (or point me to) what the differences are in these two?
I have a database table called Animals which I drag on to my Linq to SQL DBML file.
This creates me a class called Animal.
I then create a class to extend it, like so:
public partial class Animal{
//my extra code here
}
But what I also want to do is have a class like this:
public class Zebra : Animal{
//even more extra code here
}
The trouble is I get an InvalidCastException from my repository, when I do this:
Animal a = dataContext.Animals.Where(c=>c.id.Equals(id)).SingleOrDefault();
return (Zebra)a;
I've stripped back my classes to the point where they're completely empty in an attempt to work why it doesn't work. To no avail.
This casting process did used to work in the non-LINQ-2-SQL project that I'm switching to MVC/LINQ.
I want to delete entity from linq class this entity has one to many relationshipe with another table so I want to delete all entities related to this one for example I want to delete classroom so i should delete all student is this classroom fisrt i don't how to delete all these student in one time
View 1 RepliesI want to create a LINQ DataContext Class as per Database Design. I getting a problem in some cases.
the syntax to bulid a LINQ class :
[Code]....
Here Table Name Is HardCoded But I my case my Table Name A Changed as Finicial Year Change.So How I Give The TableName As RunTime
I have added a partial class to one generated by the Entity Framework. I wanted to add a calculated field that I could bind to my GridView. However, when I try to access the new property, I get an error message that this is a limitation to Entity Framework.Are there any work arounds to accomplish this?
View 1 RepliesThe problem is I had to create a draftResult class in order to show data that resides in two different tables using linq which means if i want to add or remove a column i will need to do so in the draftresult and in my linq. Here's what my setup looks like: I have two tables (draft, lookUpStatus)
draft table columns
idname,status id
lookupStatus
idtitle
public class draftResult {
public string draftName {get; set;}
public string status {get; set;}
}
I want to list the draft name and the status title in a table view. In order to do this, I wrote the following linq in a method in my sqlRepository class and return it to a IQueryable<draftResult>. My controller instanstiates the sqlRepository object and invokes GetDraftListing().
public class sqlRepository {
private Table<Draft> _draft;
private Table<LookUpStatus> _lookupubStatus;
public IQueryable<draftResult> GetDrafLtisting() {
return (from draft in _draft
join status in _lookuptatus
on draft.StatusID equals status.ID
select new draftResult
{
draftName = draft.name,
status = status.Title
});
}
}
The above process works but does not seem as flexible and i'm trying to get a better understanding of MVC and LINQ.
i have created basic .aspx files .one is login.aspx and registration.aspx...Now in my solution explorer i also added class file i.e StudentInfo.cs and wrote some properties in it...now my question is
1. i want to connect Studentinfo.cs class to my login.aspx.cs...So that i can call the methods in Studentinfo.cs..how to do it?
I have a problem. (this a simplfied example)
In Entity framework I have a class which is effectively
fooEntity
{
public Guid Id {get; set;}
and a collection of fooChildEntity
}
a fooChildEntity is again an entityframework class
fooChildEntity
{
public Guid kidId {get; set;}
}
Now I also have a pair of business layer classes foo and fooChild
foo
{
public Guid Id {get; set;}
ilist<fooChild> Children {get;set;}
}
fooChild
{
public Guid kidId {get; set;}
}
My aim is to write a linq to entites that will allow me to convert the entity foo and children into the business foo and children without breaking deferred execution ( I will be adding filters to reduce the recordset at a higher coding level in the business layer)
doing something like
this.context.fooEntity
.include(fooChildEntity)
.Select( fe => new foo { Id=fe.Id ,
fe.foreach(fec => Children.add( new fooChild { kidId = fec.kidId}))})
.AsIQueryable()
is plainly rubbish and would never compile - it is however an indication of the direction I was thinking .
Even if I got a foreach to work like that or similar it would break deferred execution
At this point there are around 300,000 foo entities which I will eventualy filter to 5 or 6 foo's - this is why deferred execution is needed.
In my company one of the applications is a classic asp based application.In this application one the .asp has a Class Definition and a function associated with the class.I want to use this class an aspx.cs page.Is it possible to do this and how
View 3 RepliesI am following the Nerd Dinner tutorial as I'm learning ASP.NET MVC, and I am currently on Step 3: Building the Model. One part of this section discusses how to integrate validation and business rule logic with the model classes. All this makes perfect sense. However, in the case of this source code, the author only validates one class: Dinner.
What I am wondering is, say I have multiple classes that need validation (Dinner, Guest, etc). It doesn't seem smart to me to repeatedly write these two methods in the partial class:
[code]....
This doesn't "feel" right, but I wanted to check with SO to get opinions of individuals smarter than me on this. I also tested it out, and it seems that the partial keyword on the OnValidate method is causing problems (understandably so). This doesn't seem possible to fix (but I could very well be wrong).
I've developed a class and it is put in a .cs file under the app_code folder. The class is a public one and there is no namespace specifically defined for this class in the file.of my webpages uses this class. It works ok on my local machine. However after I uploaded the page to the web server and then try to display the page through internet, the sever told me the class name can not be found.
View 3 RepliesIs there a method to retrieve the file name of a class?
Specifically I would like to create a static method (CreateLink) in a base class (BasePage) to automatically return the path and filename of the page called.
I code in .C# ASP.NET
private const string TEMPLATE = "~/One.aspx";
public static HyperLink CreateLink()
{
HyperLink link = new HyperLink();
link.Text = "Click here";
link.NavigateUrl = String.Format(TEMPLATE);
return link;
}
Is it possible to avoid the use of TEMPLATE hardcoded variable? Is it possible to retrieve the One.aspx path from file name and location?