|
Hello,
I am a new in EF.
I have a Customewr class:
public class Customer
{
public int CustomerId { get; set; }
public string Name { get; set; }
public string Email { get; set; }
}
And here is my DbContext class:
public class DiveShopContext:DbContext
{
public DbSet<Customer> Customers { get; set; }
}
I want to be able to save Customers to my DB, i do it as follow:
<pre lang="cs">class Program
{
static void Main(string[] args)
{
using (var db = new DiveShopContext())
{
var customer = new Customer();
customer.CustomerId = 3045;
customer.Name = "Alex";
db.Customers.Add(customer);
db.SaveChanges();
}
}
}</pre>
Every thing is saved fine but the CustomerId is changed from 3045 to 1 and saved.
|
|
|
|
|
Presumably what you actually mean is that when you save it and then look at the saved customer that the customer id is then 1 instead as you expected being 2945.
Presuming that you are in fact looking at the correct database/table/column then I would suppose that the specific column is an auto index column. And you shouldn't be attempting to set the id in the first place.
|
|
|
|
|
columbos14927 wrote: but the CustomerId is changed from 3045 to 1 and save
I am going to guess that CustomerID at the database level is an Identity Column? If that's the case then the value you are trying to set is not going to be accepted by the database engine.
Common sense is admitting there is cause and effect and that you can exert some control over what you understand.
|
|
|
|
|
|
|
|
|
I have my inner query is giving me only parent
but I want to make use of the result of the
inner query again as input till I did not find
any child ,so I am using procedure as I have to
collect all the parent I get from the inner query
and then update the outer query using the inner query
result.it is the requirement what I want to achive,
e.g
update table A
set A.a as "xyz"
//here I will get t
where A.id in
(
select A.child_id from A,B,C
--I get the child by passing parent as input and again consider the child A.child_id as parent
and find the child
where A.id= b.id
b.name = x and A.prent_id = ?
//few join condtion here
)
e.g
input 1 result 1.1
input 1.1 result 1.1.1
input 1.1.1 result 1.1.1.1
update A
where A.id in
('1.1','1.1.1','1.1.1.1')--here I want to use a container and make use of it
Thanks for your response
|
|
|
|
|
ramina sen wrote: I am using procedure as I have to
collect all the parent I get from the inner query, How about putting that into a temporary table and work with that?
Bastard Programmer from Hell
If you can't read my code, try converting it here[^]
|
|
|
|
|
Hi,
I've used the following expression, to define the number of rows per page.
=Int((RowNumber(Nothing)-1)/50)
However the last row is displaying on a new page although the previous page does not exceed 50 rows.
How can I prevent the last row from displaying on a new page?
|
|
|
|
|
I suspect the whole concept of defining a page length based on the number of rows is wrong. What happens if you reduce the height of the rows slightly. Page size has a defined length and each element within the page has it's own dimensions (rows, header, footer and groups) all of which affect the placement of the data relative to the page length.
Never underestimate the power of human stupidity
RAH
|
|
|
|
|
I have two tables in MS-Access "tmpChanges" (685 records) and "tmpChangesWithDates" (785 records). I want to design a query that will only show those 100 records that are the difference between the two tables. Each has 4 fields and are common to both tables: State, City, Sale, SaleDate. The table "tmpChanges" has no value listed in the SaleDate field. I tried this and it did not work, any clues?:
SELECT tmpChangesWithDates.City, tmpChangesWithDates.State, tmpChangesWithDates.Sale, tmpChangesWithDates.SaleDate
FROM tmpChangesWithDates LEFT JOIN tmpChanges ON tmpChangesWithDates.[Sale] = tmpChanges.[Sale]
WHERE (((tmpChanges.SaleDate) Is Null));
|
|
|
|
|
BennyCriziko wrote: any clues You got the wrong join if you're looking for differences. I'd do it with a "WHERE NOT IN" and a subquery.
Bastard Programmer from Hell
If you can't read my code, try converting it here[^]
|
|
|
|
|
Like this?:
SELECT tmpChangesWithDates.City, tmpChangesWithDates.State,
tmpChangesWithDates.Sale, tmpChangesWithDates.SaleDate
FROM tmpChangesWithDates
WHERE NOT IN
(SELECT tmpChangesWithDates.City, tmpChangesWithDates.State,
tmpChangesWithDates.Sale, tmpChangesWithDates.SaleDate
FROM tmpChangesWithDates LEFT JOIN tmpChanges ON
tmpChangesWithDates.[Sale] = tmpChanges.[Sale]
WHERE (((tmpChanges.SaleDate) Is Null)));
|
|
|
|
|
If the result is correct, then yes
Bastard Programmer from Hell
If you can't read my code, try converting it here[^]
|
|
|
|
|
SELECT tmpChangesWithDates.City, tmpChangesWithDates.State, tmpChangesWithDates.Sale, tmpChangesWithDates.SaleDate
FROM tmpChangesWithDates LEFT OUTER JOIN tmpChanges ON tmpChangesWithDates.[Sale] = tmpChanges.[Sale]
WHERE (((tmpChanges.SaleDate) Is Null));
=========================================================
I'm an optoholic - my glass is always half full of vodka.
=========================================================
|
|
|
|
|
Hi Guys,
I have a condition that, I have to display data for all states with 3 different conditions like
i have a state column and i have to calculate count for judicial, non-judicial , and redemption these columns i have to display for each state how can i make it happen in a single query with good performance.
I have 3 different conditions to get count, so please help me
ex
<table border="1" cellpadding="3">
<tr>
<th>
State
</th>
<th>
Judicial
</th>
<th>
Non-Judicial
</th>
<th>
Redumtion
</th>
</tr>
<tr>
<td>
AZ
</td>
<td>
10
</td>
<td>
01
</td>
<td>
0
</td>
</tr>
<tr>
<td>
CA
</td>
<td>
12
</td>
<td>
94
</td>
<td>
04
</td>
</tr>
<tr>
<td>
NV
</td>
<td>
32
</td>
<td>
04
</td>
<td>
04
</td>
</tr>
<tr>
<td>
QA
</td>
<td>
32
</td>
<td>
49
</td>
<td>
04
</td>
</tr>
</table>
|
|
|
|
|
Fix your formatting.
What is your table structure?
In general, you should be able to do that using GROUP BY clause and SUM() aggregate function.
|
|
|
|
|
As Shameel said, something like this should work:
SELECT
State,
Sum(Case When TheColumn = 'Judicial' Then 1 Else 0 End) As JudicialCount,
Sum(Case When TheColumn = 'Non-Judicial' Then 1 Else 0 End) As NonJudicialCount,
Sum(Case When TheColumn = 'Redemption' Then 1 Else 0 End) As RedemptionCount
FROM
YourTable
GROUP BY
State
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
Thank you Richard Deeming. i written query like what you have written, is this style of query takes less execution time ?
|
|
|
|
|
VishwaKL wrote: is this style of query takes less execution time ?
Less than what? You'd need to measure the performance of this query against the query you want to compare it to.
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
Welcome to the database forum; as you have noticed, it focuses on SQL and databases. Are you by any chance looking for an XPath-query?
Bastard Programmer from Hell
If you can't read my code, try converting it here[^]
|
|
|
|
|
I want to write a procedure
1.find the child of a parent recursively till we do not find any child.
2.Then collect all the child in get in step one and update the value of name of all the child-->second procedure
approach:
1. write a procedure to take all the parent as input
2. write a procedure to find child recursively till we do not find any child further
e.g
1:parent
1.1 child
now consider 1.1 as parent and find child e.g 1.2
recursively call and collect and then update all the child name
proc 2: simple procedure with update where id ("child we got previously ")
I got the logic but do not know how to call recursively the procedure and hold the values of child
any sample code or input is highly appreciated!!!
Thanks,
Ramina
|
|
|
|
|
ramina sen wrote: any sample code or input is highly appreciated!!!
MSDN[^], see the heading "Using a recursive CTE in an UPDATE statement". More info, also on MSDN[^]
Bastard Programmer from Hell
If you can't read my code, try converting it here[^]
|
|
|
|
|
Is there some reason for doing this recursively, you should be able to achieve a simple update in one sql statement using an inner join!
Never underestimate the power of human stupidity
RAH
|
|
|
|